Submission #1495384


Source Code Expand

#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  string s;
  cin >> n >> s;
  bool ss[n];

  ss[0] = true; ss[1] = true;
  for (int i = 2; i < n; ++i) {
    if ((ss[i-1] && s[i-1]=='o' ) || (!ss[i-1] && s[i-1]=='x')) ss[i] = ss[i-2];
    else ss[i] = !ss[i-2];
  }
  if ((ss[n-1] && s[n-1]=='o' && ss[0]==ss[n-2]) || (ss[n-1] && s[n-1]=='x' && ss[0]!=ss[n-2]) ||
  (!ss[n-1] && s[n-1]=='o' && ss[0]!=ss[n-2]) || (!ss[n-1] && s[n-1]=='x' && ss[0]==ss[n-2])) {
    if ((ss[0] && s[0]=='o' && ss[1]==ss[n-1]) || (ss[0] && s[0]=='x' && ss[1]!=ss[n-1]) ||
    (!ss[0] && s[0]=='o' && ss[1]!=ss[n-1]) || (!ss[0] && s[0]=='x' && ss[1]==ss[n-1])) {
      for (int i = 0; i < n; ++i) cout << (ss[i] ? "S" : "W");
      cout << endl;
      return 0;
    }
  }

  ss[0] = true; ss[1] = false;
  for (int i = 2; i < n; ++i) {
    if ((ss[i-1] && s[i-1]=='o' ) || (!ss[i-1] && s[i-1]=='x')) ss[i] = ss[i-2];
    else ss[i] = !ss[i-2];
  }
  if ((ss[n-1] && s[n-1]=='o' && ss[0]==ss[n-2]) || (ss[n-1] && s[n-1]=='x' && ss[0]!=ss[n-2]) ||
  (!ss[n-1] && s[n-1]=='o' && ss[0]!=ss[n-2]) || (!ss[n-1] && s[n-1]=='x' && ss[0]==ss[n-2])) {
    if ((ss[0] && s[0]=='o' && ss[1]==ss[n-1]) || (ss[0] && s[0]=='x' && ss[1]!=ss[n-1]) ||
    (!ss[0] && s[0]=='o' && ss[1]!=ss[n-1]) || (!ss[0] && s[0]=='x' && ss[1]==ss[n-1])) {
      for (int i = 0; i < n; ++i) cout << (ss[i] ? "S" : "W");
      cout << endl;
      return 0;
    }
  }

  ss[0] = false; ss[1] = true;
  for (int i = 2; i < n; ++i) {
    if ((ss[i-1] && s[i-1]=='o' ) || (!ss[i-1] && s[i-1]=='x')) ss[i] = ss[i-2];
    else ss[i] = !ss[i-2];
  }
  if ((ss[n-1] && s[n-1]=='o' && ss[0]==ss[n-2]) || (ss[n-1] && s[n-1]=='x' && ss[0]!=ss[n-2]) ||
  (!ss[n-1] && s[n-1]=='o' && ss[0]!=ss[n-2]) || (!ss[n-1] && s[n-1]=='x' && ss[0]==ss[n-2])) {
    if ((ss[0] && s[0]=='o' && ss[1]==ss[n-1]) || (ss[0] && s[0]=='x' && ss[1]!=ss[n-1]) ||
    (!ss[0] && s[0]=='o' && ss[1]!=ss[n-1]) || (!ss[0] && s[0]=='x' && ss[1]==ss[n-1])) {
      for (int i = 0; i < n; ++i) cout << (ss[i] ? "S" : "W");
      cout << endl;
      return 0;
    }
  }

  ss[0] = false; ss[1] = false;
  for (int i = 2; i < n; ++i) {
    if ((ss[i-1] && s[i-1]=='o' ) || (!ss[i-1] && s[i-1]=='x')) ss[i] = ss[i-2];
    else ss[i] = !ss[i-2];
  }
  if ((ss[n-1] && s[n-1]=='o' && ss[0]==ss[n-2]) || (ss[n-1] && s[n-1]=='x' && ss[0]!=ss[n-2]) ||
  (!ss[n-1] && s[n-1]=='o' && ss[0]!=ss[n-2]) || (!ss[n-1] && s[n-1]=='x' && ss[0]==ss[n-2])) {
    if ((ss[0] && s[0]=='o' && ss[1]==ss[n-1]) || (ss[0] && s[0]=='x' && ss[1]!=ss[n-1]) ||
    (!ss[0] && s[0]=='o' && ss[1]!=ss[n-1]) || (!ss[0] && s[0]=='x' && ss[1]==ss[n-1])) {
      for (int i = 0; i < n; ++i) cout << (ss[i] ? "S" : "W");
      cout << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}

Submission Info

Submission Time
Task D - Menagerie
User knk
Language C++14 (GCC 5.4.1)
Score 500
Code Size 3134 Byte
Status AC
Exec Time 6 ms
Memory 720 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 4 ms 512 KB
02.txt AC 3 ms 384 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 5 ms 640 KB
06.txt AC 4 ms 640 KB
07.txt AC 2 ms 384 KB
08.txt AC 2 ms 384 KB
09.txt AC 1 ms 256 KB
10.txt AC 2 ms 256 KB
11.txt AC 6 ms 720 KB
12.txt AC 6 ms 720 KB
13.txt AC 6 ms 720 KB