Submission #1116259


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;



inline char op(char c)
{
    return c == 'S' ? 'W' : 'S';
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    string a;
    cin >> a;

    string t;
    for (int i = 0; i <= n; i++) {
        t.push_back(' ');
    }
    for (int f = 0; f < 2; f++) {
        for (int s = 0; s < 2; s++) {
            t[0] = (f == 0 ? 'S' : 'W');
            t[1] = (s == 0 ? 'S' : 'W');

            for (int i = 1; i < n; i++) {
                if (t[i] == 'S') {
                    if (a[i] == 'o') {
                        t[i + 1] = t[i - 1];
                    } else {
                        t[i + 1] = op(t[i - 1]);
                    }
                } else {
                    if (a[i] == 'o') {
                        t[i + 1] = op(t[i - 1]);
                    } else {
                        t[i + 1] = t[i - 1];
                    }
                }
            }
            bool ok = false;
            if (t[0] == 'S') {
                    if (a[0] == 'o') {
                        ok = t[n - 1] == t[1];
                    } else {
                        ok = t[n - 1] == op(t[1]);
                    }
                } else {
                    if (a[0] == 'o') {
                                    ok = t[n - 1] == op(t[1]);
                    } else {
                                                ok = t[n - 1] == t[1];

                    }
                }

            if (t[n] == t[0] and ok) {
                t.resize(n);
                cout << t << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Menagerie
User Dener
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1758 Byte
Status
Exec Time 5 ms
Memory 720 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 500 / 500 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 1 ms 256 KB
00_example_02.txt 1 ms 256 KB
00_example_03.txt 1 ms 256 KB
01.txt 3 ms 512 KB
02.txt 2 ms 512 KB
03.txt 1 ms 256 KB
04.txt 1 ms 256 KB
05.txt 4 ms 640 KB
06.txt 2 ms 640 KB
07.txt 2 ms 384 KB
08.txt 2 ms 384 KB
09.txt 1 ms 256 KB
10.txt 2 ms 384 KB
11.txt 5 ms 720 KB
12.txt 5 ms 720 KB
13.txt 4 ms 720 KB