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 15:08:11
2017-05-27 14:59:13
2017-05-27 13:45:44
Task:HIIT game
Sender:IOG
Submission time:2017-05-27 15:08:11
Status:READY
Result:TIME LIMIT EXCEEDED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;



inline int findh(string& s, unordered_set<int>& set)
{
    const char* hiit = "HIIT";
    int hidx = 0;
    unsigned int i = 0;
    int space = 0;
    
    //for (auto x : set)
    //    cout << x << endl;
    
    
    for (;i < s.size();)
    {
        if (set.count((int)i))
            space += 4;
        
        if (space == 0)
        {
            if (s[i] == hiit[hidx])
            {
                hidx++;
            }
            else 
            {
                hidx = 0;
                if (s[i] == hiit[hidx])
                    hidx++;
            }
        }
        
        //cout << hidx << endl;
        
        if (hidx == 4)
            return (i - 3);
        
        
        i++;
        if (space > 0)
        --space;
    }
    
    return -1;
}

int main(void)
{
 cin.sync_with_stdio(0);
 cin.tie(0);
 string s;
 
 cin >> s;
 
 unordered_set<int> set; 
 
 //int start = 0;
 int player = 0;
 
 for(;;)
 {
     //cout << s << endl;
     int p = findh(s, set);
     //cout << start << "\n";
     //cout << "p " <<  p << endl;
     if (p != -1)
     {
         player += 1;
         
         set.insert(p);
         
     }else {
         if (player % 2 == 1)
             cout << "Uolevi" << endl;
         else cout << "Maija" << endl;
      
         return 0;
     }
}
}