Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 11:42:03
2017-05-27 11:33:16
Task:HIIT game
Sender:Nää jäbät
Submission time:2017-05-27 11:42:03
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int f(int, int)':
input/code.cpp:13:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (e[i] || i == s.length() - 4) return NIL;
                                   ^
input/code.cpp: In function 'int main()':
input/code.cpp:65:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.length() - 4; i++) {
                                      ^

Code

#include <bits/stdc++.h>

#define ll long long

using namespace std;

string s;
int e[1111111];
int NIL = 13371337;
int am = 0;

int f (int i, int k) {
    if (e[i] || i == s.length() - 4) return NIL;
    e[i] = 1;
    if (k == 0) {
        if (s[i] != 'H') e[i] = 0;
        if (s[i] != 'H') return NIL;
        int y = i;
        while (s[y + 1] == 'H') {
            int x = f(y + 1, 0);
            if (x == NIL) e[i] = 0;
            if (x == NIL) return NIL;
            y = x;
        }
        int x = f(y + 1, k + 1);
        if (x == NIL) e[i] = 0;
        return x;
    } else if (k == 3) {
        if (s[i] != 'T') e[i] = 0;
        if (s[i] != 'T') return NIL;
        am++;
        return i;
    } else {
        if (s[i] != 'I') e[i] = 0;
        if (s[i] != 'I') return NIL;
        if (k == 1) {
            int y = i;
            while (s[y + 1] == 'H') {
                int x = f(y + 1, 0);
                if (x == NIL) e[i] = 0;
                if (x == NIL) return NIL;
                y = x;
            }
            int x = f(y + 1, k + 1);
            if (x == NIL) e[i] = 0;
            return x;
        } else {
            int y = i;
            while (s[y + 1] == 'H') {
                int x = f(y + 1, 0);
                if (x == NIL) e[i] = 0;
                if (x == NIL) return NIL;
                y = x;
            }
            int x = f(y + 1, k + 1);
            if (x == NIL) e[i] = 0;
            return x;
        }
    }
}

int main () {
    cin>>s;
    s += "####";
    for (int i = 0; i < s.length() - 4; i++) {
        if (s[i] == 'H') {
            f(i, 0);
        }
    }
    /*for (int i = 0; i < s.length() - 4; i++) {
        cout<<e[i];
    }
    cout<<endl;
    cout<<am<<endl;*/
    if (am % 2) cout<<"Uolevi"<<endl;
    else cout<<"Maija"<<endl;
}