Submission #1118018
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 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;
}
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( cal(ans,ani,N,1) ){
return;
}
if( cal(ans,ani,N,2) ){
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 |
0 |
Code Size |
3185 Byte |
Status |
WA |
Exec Time |
11 ms |
Memory |
896 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 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 |
WA |
7 ms |
644 KB |
02.txt |
AC |
4 ms |
512 KB |
03.txt |
AC |
1 ms |
256 KB |
04.txt |
WA |
1 ms |
256 KB |
05.txt |
WA |
10 ms |
796 KB |
06.txt |
AC |
7 ms |
896 KB |
07.txt |
WA |
3 ms |
384 KB |
08.txt |
AC |
2 ms |
384 KB |
09.txt |
AC |
2 ms |
256 KB |
10.txt |
AC |
3 ms |
384 KB |
11.txt |
WA |
11 ms |
848 KB |
12.txt |
WA |
11 ms |
848 KB |
13.txt |
WA |
11 ms |
848 KB |