Submission #1248874


Source Code Expand

#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define print(x) cout<<x<<endl;
typedef long long ll;

int n;
string s;
int int_s;
int ans[100005];
string ans_s[100005];
int flag = 0;

bool is(int s1, int s2) {
	ans[0] = s1;	//ans[i]=-1のとき羊、1の時狼
	ans[1] = s2;
	rep(i, 1, n) {
		if (ans[i] == -1 && s[i] == 'o') { ans[i + 1] = ans[i - 1]; }
		else if (ans[i] == -1 && s[i] == 'x') { ans[i + 1] = -ans[i-1]; }
		else if (ans[i] == 1 && s[i] == 'o') { ans[i + 1] = -ans[i - 1]; }
		else if (ans[i] == 1 && s[i] == 'x') { ans[i + 1] = ans[i - 1]; }
	}
	//rep(i, 0, n )cout << ans[i];
	//cout << endl;
	int flag = 0;
	if (ans[n - 1] == -1 && s[n - 1] == 'o'&&ans[n - 2] == ans[0] \
		|| ans[n - 1] == -1 && s[n - 1] == 'x'&&ans[n - 2] != ans[0] \
		|| ans[n - 1] == 1 && s[n - 1] == 'o'&&ans[n - 2] != ans[0]\
		|| ans[n - 1] == 1 && s[n - 1] == 'x'&&ans[n - 2] == ans[0]) flag += 1;
	if (ans[0] == -1 && s[0] == 'o'&&ans[n - 1] == ans[1] \
		|| ans[0] == -1 && s[0] == 'x'&&ans[n - 1] != ans[1] \
		|| ans[0] == 1 && s[0] == 'o'&&ans[n - 1] != ans[1] \
		|| ans[0] == 1 && s[0] == 'x'&&ans[n - 1] == ans[1]) flag += 1;
	if (flag == 2)return 1;
	return 0;
}

int main() {

	cin >> n;
	cin >> s;
	int sw[8] = { -1,-1,-1,1,1,-1,1,1};
	for(int i=0;i<8;i+=2) {
		//print(j);
		if (is(sw[i], sw[i+1])) {
			rep(j, 0, n) {
				if (ans[j] == -1) { ans_s[j] = 'S'; }
				else if (ans[j] == 1) { ans_s[j] = 'W'; }
			}
			rep(j, 0, n) { cout<<ans_s[j];}
			cout << endl;
			return 0;
		}
	}
	
	print(-1); return 0;
}

Submission Info

Submission Time
Task D - Menagerie
User ttakano
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1638 Byte
Status AC
Exec Time 19 ms
Memory 6272 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 2 ms 1024 KB
00_example_02.txt AC 2 ms 1024 KB
00_example_03.txt AC 2 ms 1024 KB
01.txt AC 12 ms 4352 KB
02.txt AC 9 ms 3456 KB
03.txt AC 2 ms 1024 KB
04.txt AC 2 ms 1024 KB
05.txt AC 17 ms 5760 KB
06.txt AC 16 ms 5760 KB
07.txt AC 4 ms 1792 KB
08.txt AC 4 ms 1920 KB
09.txt AC 2 ms 1280 KB
10.txt AC 3 ms 1152 KB
11.txt AC 19 ms 6272 KB
12.txt AC 19 ms 6272 KB
13.txt AC 19 ms 6272 KB