Submission #1118885
Source Code Expand
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)
#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
/*inline T gcd(T a,T b){
while(b != 0 ){
a = a % b;
swap(a,b);
}
return a;
}*/
// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////
bool check(bool L,bool M,bool R,bool ans){
if( M == true && ans == true ){
return L==R;
}
if( M == true && ans == false ){
return L!=R;
}
if( M == false && ans == true ){
return L!=R;
}
if( M == false && ans == false ){
return L==R;
}
return false;
}
bool cal(vector<bool> ans,vector<bool> ani,int N,int start){
vector< int > chan(N,0);
int pos = start;
int L,R;
int loop = 0;
int Count = 0;
const int Limit = 3;
bool flag = true;
while( loop<N ){
loop++;
Count++;
L = (pos+N-1)%N;
R = (pos+1)%N;
if( ani[pos] == true){//s
if( ans[pos] == true ){//両側同じ
if( ani[L] != ani[R] ){
ani[R] = ani[L];
loop = 0;
chan[R]++;
if( chan[R] >= Limit ){
flag = false;
break;
}
}
}else{//false//両側異なる
if( ani[L] == ani[R] ){
ani[R] = !ani[L];
loop = 0;
chan[R]++;
if( chan[R] >= Limit ){
flag = false;
break;
}
}
}
}else{//w
if( ans[pos] == false ){//両側同じ
if( ani[L] != ani[R] ){
ani[R] = ani[L];
loop = 0;
chan[R]++;
if( chan[R] >= Limit ){
flag = false;
break;
}
}
}else{//false//両側異なる
if( ani[L] == ani[R] ){
ani[R] = !ani[L];
loop = 0;
chan[R]++;
if( chan[R] >= Limit ){
flag = false;
break;
}
}
}
}
pos = (pos+1)%N;
}
if( loop == N ){
for(int i=0;i<N;++i){
if( ani[i] ){
cout << "S";
}else{
cout << "W";
}
}cout << endl;
return true;
}
return false;
}
bool cal2(vector<bool> ans,vector<bool> ani,int N,int start){
//0-2は正しい配置
int L,R;
L = (start+N-1)%N;
R = (start+1)%N;
int _R,R_,_L,L_;
bool flag;
for(int i=0;i<=N/2;++i){
flag = true;
_R = (R+N-1)%N;
R_ = (R+1)%N;
_L = (L+N-1)%N;
L_ = (L+1)%N;
if( check(ani[_R],ani[R],ani[R_],ans[R]) == false ){
bool to = false;
if( ani[_R] ) to = !to;
if( ani[R] ) to = !to;
if( ans[R] ) to = !to;
ani[R_] = to;
}
if( check(ani[_L],ani[L],ani[L_],ans[L]) == false ){
bool to = false;
if( ani[L_] ) to = !to;
if( ani[L] ) to = !to;
if( ans[L] ) to = !to;
ani[_L] = to;
}
L = (L+N-1)%N;
R = (R+1)%N;
if( L<R ) break;
}
for(int i=0;i<N;++i){
L = (i+N-1) %N;
R = (i+1)%N;
if( check(ani[L],ani[i],ani[R],ans[i]) == false ){
return false;
}
}
for(int i=0;i<N;++i){
if( ani[i] ){
cout << "S";
}else{
cout << "W";
}
}cout << endl;
return true;
}
inline void solve(){
int N;
string str;
cin >> N >> str;
vector< bool > ans(N);//false:x true:o
vector< bool > ani(N,true);//false:w true:s
for(int i=0;i<N;++i){
if( str[i] == 'o'){
ans[i] = true;
}else{
ans[i] = false;
}
}
//if( cal(ans,ani,N,0) ){return;}
if( ans[1] == true ){
ani[0] = true;ani[1]=true;ani[2]=true;
if( cal2(ans,ani,N,1) ){return;}
ani[0] = false;ani[1]=true;ani[2]=false;
if( cal2(ans,ani,N,1) ){return;}
ani[0] = true;ani[1]=false;ani[2]=false;
if( cal2(ans,ani,N,1) ){return;}
ani[0] = false;ani[1]=false;ani[2]=true;
if( cal2(ans,ani,N,1) ){return;}
}else{
ani[0] = true;ani[1]=true;ani[2]=false;
if( cal2(ans,ani,N,1) ){return;}
ani[0] = false;ani[1]=true;ani[2]=true;
if( cal2(ans,ani,N,1) ){return;}
ani[0] = true;ani[1]=false;ani[2]=true;
if( cal2(ans,ani,N,1) ){return;}
ani[0] = false;ani[1]=false;ani[2]=false;
if( cal2(ans,ani,N,1) ){return;}
}
cout << -1 << endl;
}
signed main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
//std::cout << std::fixed;//小数を10進数表示
//cout << setprecision(16);//小数点以下の桁数を指定
solve();
}
Submission Info
Submission Time |
|
Task |
D - Menagerie |
User |
akarin55 |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
5052 Byte |
Status |
AC |
Exec Time |
14 ms |
Memory |
592 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
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 |
384 KB |
03.txt |
AC |
1 ms |
256 KB |
04.txt |
AC |
1 ms |
256 KB |
05.txt |
AC |
9 ms |
512 KB |
06.txt |
AC |
7 ms |
512 KB |
07.txt |
AC |
3 ms |
256 KB |
08.txt |
AC |
3 ms |
256 KB |
09.txt |
AC |
1 ms |
256 KB |
10.txt |
AC |
3 ms |
256 KB |
11.txt |
AC |
14 ms |
592 KB |
12.txt |
AC |
14 ms |
592 KB |
13.txt |
AC |
10 ms |
592 KB |