Submission #2703509


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define UNKNOWN 0
#define SHEEP 1
#define WOLF -1

#define SAME 1
#define OPPOSITE -1

#define HONEST 1
#define LIAR -1


int sub(int N, vi& same, int htype0, int htype1) {
    vi htypes(N, UNKNOWN);
    htypes[N-1] = htype0;
    htypes[0] = htype1;

    // htypes[N-1] = htypes[0] * htypes[1] * same[0];
    for (int i=0; i<N; ++i) {
        htypes[(i+1)%N] = htypes[i] * htypes[(i-1 +N)%N] * same[i];
        // 1,2,..N-1,0
    }
    if (htypes[N-1] == htype0 && htypes[0] == htype1) {
        // cerr << htypes << endl;
        rep(i,N) {
            putchar(htypes[i] == SHEEP ? 'S' : 'W');
        }
        putchar('\n');
        return 1;
    }
    return 0;
}

void solve(int N, string& s) {
    vector<int> same(N);
    rep(i,N) same[i] = (s[i] == 'o') ? SAME : OPPOSITE;

    int htype[2] = { HONEST, LIAR };

    rep(htype0,2) rep(htype1,2) {
        if (sub(N,same,htype[htype0],htype[htype1])) return;
    }
    cout << -1 << endl;
}

int main() {
    int N; cin >> N;
    string s; cin >> s;
    solve(N,s);
    return 0;
}

Submission Info

Submission Time
Task D - Menagerie
User naoya_t
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2801 Byte
Status
Exec Time 8 ms
Memory 1400 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 6 ms 900 KB
02.txt 3 ms 768 KB
03.txt 1 ms 256 KB
04.txt 1 ms 256 KB
05.txt 7 ms 1308 KB
06.txt 6 ms 1280 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 7 ms 1400 KB
12.txt 7 ms 1400 KB
13.txt 8 ms 1400 KB