Submission #1115942


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

char f(char a, char b, char c) {
	if (b == 'S') {
		if (c == 'o') return a;
		if (a == 'W') return 'S';
		return 'W';
	}
	if (c == 'x') return a;
	if (a == 'W') return 'S';
	return 'W';
}

int n;
string s;

bool ok(string ret) {
	char a = ret[n - 2];
	char b = ret[n - 1];
	char c = ret[0];
	char d = ret[1];
	if (f(a, b, s[n - 1]) != c) return false;
	if (f(b, c, s[0]) != d) return false;
	return true;
}

signed main() {
	cin >> n;
	cin >> s;

	string ret = "";
	ret += "SS";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	ret = "";
	ret += "SW";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	ret = "";
	ret += "WS";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	ret = "";
	ret += "WW";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	cout << -1 << endl;

    return 0;
}

Submission Info

Submission Time
Task D - Menagerie
User iwashi31
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2087 Byte
Status AC
Exec Time 9 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 5 ms 512 KB
02.txt AC 3 ms 512 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 7 ms 640 KB
06.txt AC 5 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 3 ms 256 KB
11.txt AC 9 ms 640 KB
12.txt AC 9 ms 640 KB
13.txt AC 8 ms 640 KB