Submission #150317

#TimeUsernameProblemLanguageResultExecution timeMemory
150317Torat (#200)HicCup (FXCUP4_hiccup)C++17
24 / 100
56 ms12196 KiB
#include <bits/stdc++.h>
#include "hiccup.h"
//~ #include "grader.cpp"
using namespace std;

const int N = 1000001;

int n;
string s;
vector <int> h;

bool valid(){
    int o = 0;
    for(auto &i : s){
        o += i == 'H';
        o -= i == 'C';
        if(o < 0) return 0;
    }
    if(o) return 0;
    for(auto &i : s){
        if(i == 'H') o = 0;
        else if(i == 'C') o = 1;
        else if(o == 0) return 0;
    }
    return 1;
}
bool check(int x){
    vector <int> g(n);
    for(int i = n - 1 ; i >= 0 ; i--){
        if(s[i] == '!') g[h[i]]++;
        else if(s[i] == 'C'){
            if(g[h[i]] < x) return 0;
            g[h[i]] -= x;
        }
    }
    return 1;
}
int HicCup(std::string S) {
    s = S;
    n = s.size();
    if(!valid() || s == string(n, '!')) return -1;
    h.resize(n);
    h[0] = 1;
    for(int i = 1 ; i < n ; i++){
        h[i] = h[i - 1];
        if(s[i] == 'H') h[i]++;
        else if(s[i] == 'C') h[i]--;
        //~ else v[h[i]].push_back(i);
    }
    int l = 0, r = n;
    while(l <= r){
        int mid = (l + r) / 2;
        if(check(mid)) l = mid + 1;
        else r = mid - 1;
    }
    int z = 0;
    for(int i = 0 ; i < 1000000 ; i++){
        int x = 352700;
        int y = 50398;
        z += x % y;
    }
    return l - 1;
}

Compilation message (stderr)

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:60:11: warning: iteration 42683 invokes undefined behavior [-Waggressive-loop-optimizations]
         z += x % y;
         ~~^~~~~~~~
hiccup.cpp:57:23: note: within this loop
     for(int i = 0 ; i < 1000000 ; i++){
                     ~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...