Submission #1116961


Source Code Expand

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
string ans;
char ret[MAX_N];

char nextchr(char center, char left, char a){
	if (center == 'S' && a == 'o' && left == 'S'){ return 'S'; }
	if (center == 'S' && a == 'o' && left == 'W'){ return 'W'; }
	if (center == 'S' && a == 'x' && left == 'S'){ return 'W'; }
	if (center == 'S' && a == 'x' && left == 'W'){ return 'S'; }
	if (center == 'W' && a == 'o' && left == 'S'){ return 'W'; }
	if (center == 'W' && a == 'o' && left == 'W'){ return 'S'; }
	if (center == 'W' && a == 'x' && left == 'S'){ return 'S'; }
	if (center == 'W' && a == 'x' && left == 'W'){ return 'W'; }
}

bool check(char center, char left, char right, char a){

	if ((center == 'S' && a == 'o') || (center == 'W' && a == 'x')){
		return left == right;
	}
	else{
		return left != right;
	}

}

void print(){
	rep(i, N){
		cout << ret[i];
	}
	cout << endl;
}

bool run(char first, char second){

	ret[0] = first;
	ret[1] = second;
	for (int i = 2; i < N; i++){
		ret[i] = nextchr(ret[i - 1], ret[i - 2], ans[i - 1]);
	}

	return (check(ret[0], ret[N - 1], ret[1], ans[0]) && 
		    check(ret[N - 1], ret[0], ret[N - 2], ans[N - 1]));
}

int main() {

	cin >> N;
	cin >> ans;

	bool success = false;

	if (!success){
		success = run('S', 'S');
	}
	if (!success){
		success = run('S', 'W');
	}
	if (!success){
		success = run('W', 'S');
	}
	if (!success){
		success = run('W', 'W');
	}

	if (success){
		print();
	}
	else{
		cout << -1 << endl;
	}
	
}

Submission Info

Submission Time
Task D - Menagerie
User threecourse
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2011 Byte
Status AC
Exec Time 11 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 7 ms 512 KB
02.txt AC 4 ms 512 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 7 ms 640 KB
07.txt AC 2 ms 256 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 11 ms 640 KB
12.txt AC 11 ms 640 KB
13.txt AC 10 ms 640 KB