Submission #1654471


Source Code Expand

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int n; string str;
bool ani[100000];

//1 is sheep, 0 is wolf
bool solve(bool a, bool b){
  ani[0]=a; ani[1]=b;
  int idx=2;
  while(idx <= n-1){
    if((ani[idx-1] == 1 && str[idx-1] == 'o') ||
    (ani[idx-1] == 0 && str[idx-1] == 'x')){
          ani[idx]=ani[idx-2];
    }else{
      ani[idx]=!(ani[idx-2]);
    }
    idx++;
  }

  if((ani[n-1] == 1 && str[n-1] == 'o') ||
  (ani[n-1] == 0 && str[n-1] == 'x')){
    if(ani[n-2] != ani[0]){
      return false;
    }
    else{
      if((ani[0] == 1 && str[0] == 'o') ||
      (ani[0] == 0 && str[0] == 'x')){
        if(ani[n-1] == ani[1]) return true;
        else return false;
      }else{
        if(ani[n-1] == ani[1]) return false;
        else return true;
      }
    }
  }else{
    if(ani[n-2] == ani[0]) return false;
    else{
      if((ani[0] == 1 && str[0] == 'o') ||
      (ani[0] == 0 && str[0] == 'x')){
        if(ani[n-1] == ani[1]) return true;
        else return false;
      }else{
        if(ani[n-1] == ani[1]) return false;
        else return true;
      }
    }
  }
}

void print(){
  for(int i=0;i<n;i++){
    if(ani[i]) cout << 'S';
    else cout << 'W';
  }
  cout << endl;
}

int main(){
  cin >> n >> str;
  if(solve(1, 1)){
    print();
  }else if(solve(0, 0)){
    print();
  }else if(solve(0, 1)){
    print();
  }else if(solve(1, 0)){
    print();
  }else{
    cout << -1 << endl;
  }
}

Submission Info

Submission Time
Task D - Menagerie
User emonosuke
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1575 Byte
Status AC
Exec Time 9 ms
Memory 640 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 16
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
00_example_03.txt AC 1 ms 256 KB
01.txt AC 6 ms 512 KB
02.txt AC 4 ms 384 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 9 ms 640 KB
06.txt AC 8 ms 640 KB
07.txt AC 2 ms 256 KB
08.txt AC 3 ms 384 KB
09.txt AC 1 ms 256 KB
10.txt AC 2 ms 256 KB
11.txt AC 9 ms 640 KB
12.txt AC 9 ms 640 KB
13.txt AC 9 ms 640 KB