Submission #2557861


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 100001;
const ll W = 1;
const ll S = 0;
int n,ani[N];
string s;

void animal(int a1,int a2){
	ani[0]=a1;ani[1]=a2;
	FOR(i,2,n){
		if(ani[i-1]==W && s[i-1]=='o'){
			if(ani[i-2]==W)ani[i]=S;
			else ani[i]=W;
		}else if(ani[i-1]==W && s[i-1]=='x'){
			if(ani[i-2]==W)ani[i]=W;
			else ani[i]=S;
		}else if(ani[i-1]==S && s[i-1]=='o'){
			if(ani[i-2]==W)ani[i]=W;
			else ani[i]=S;
		}else if(ani[i-1]==S && s[i-1]=='x'){
			if(ani[i-2]==W)ani[i]=S;
			else ani[i]=W;
		}
	}
}
void priani(){
	FOR(i,0,n){
		if(ani[i]==W)cout<<'W';
		else cout<<'S';
	}
	cout<<endl;
}

bool nop(int x){
	int y=x-1;if(y<0)y=n-1;
	int z=x+1;if(z==n)z=0;
	if(s[x]=='o'&&ani[x]==S){
		if(ani[y]==ani[z])return true;
	}
	if(s[x]=='x'&&ani[x]==S){
		if(ani[y]!=ani[z])return true;
	}
	if(s[x]=='o'&&ani[x]==W){
		if(ani[y]!=ani[z])return true;
	}
	if(s[x]=='x'&&ani[x]==W){
		if(ani[y]==ani[z])return true;
	}
	return false;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>s;
	animal(W,W);
	if(nop(0)&&nop(n-1)){
		priani();
		return 0;
	}
	animal(W,S);
	if(nop(0)&&nop(n-1)){
		priani();
		return 0;
	}
	animal(S,W);
	if(nop(0)&&nop(n-1)){
		priani();
		return 0;
	}
	animal(S,S);
	if(nop(0)&&nop(n-1)){
		priani();
		return 0;
	}
	pri(-1);
	return 0;
}

Submission Info

Submission Time
Task D - Menagerie
User kenta2997
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2249 Byte
Status AC
Exec Time 6 ms
Memory 976 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 768 KB
02.txt AC 3 ms 640 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 5 ms 896 KB
06.txt AC 6 ms 896 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 384 KB
11.txt AC 5 ms 976 KB
12.txt AC 5 ms 976 KB
13.txt AC 6 ms 976 KB