Submission #150847

# Submission time Handle Problem Language Result Execution time Memory
150847 2019-09-01T08:59:16 Z usa1+samsung2(#3703, adman, nona1314, wowoto9772) HicCup (FXCUP4_hiccup) C++17
24 / 100
43 ms 5492 KB
#include "hiccup.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

bool pred(const vector<int>& v, const int& g) {
    int rem = 0;
    for(int i=0; i<(int)v.size(); i++){
        if(v[i] >= g) {
            rem += v[i]-g;
        } else if ((v[i]+rem) >= g) {
            rem += v[i]+rem-g;
        } else return false;
    }
    return true;
}

int HicCup(std::string S) {
	int N = S.size();
        int x = 0;
        int lo = 0;
        int hi = 0;
        int ans = 0;
        vector<int> v;
        if (N==0) return 0;
        if (S[0] != 'H') return -1;

        {
            char ex = S[0];
            stack<char> stk;
            stk.push('H');
            for(int i = 1 ; i < N;i++) {
                const char &s = S[i];
                if((s != 'H') && (s!='C') && (s!='!')){
                    return -1;
                }
                switch(ex) {
                    case 'H':
                        if(s=='!') {
                            return -1;
                        }
                        break;
                    case 'C':
                        break;
                    case '!':
                        break;
                    default:
                        return -1;
                        break;
                }
                if(s!='!') ex = s;
                if(s=='H') stk.push('H');
                else if(s=='C') {
                    if(!stk.empty()) stk.pop();
                    else return -1;
                }
            }
            if(ex=='H' || !stk.empty()) return -1;
        }
        for(int i=N-1;i>=0;i--) {
            if(S[i] == '!') x++;
            else if(S[i] == 'C') {
                v.push_back(x);
                hi = max(hi, x);
                x=0;
            }
        }
        {
            int mid;
            while(lo<=hi){
                mid = (lo+hi)/2;
                if(pred(v, mid)) {
                    ans = max(ans, mid);
                    lo = mid + 1;
                } else {
                    hi = mid - 1;
                }
            }
        }
        return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 32 ms 5492 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 14 ms 3352 KB Output is correct
8 Correct 33 ms 5484 KB Output is correct
9 Correct 43 ms 5484 KB Output is correct
10 Correct 14 ms 3328 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 32 ms 5492 KB Output is correct
6 Correct 12 ms 3328 KB Output is correct
7 Correct 14 ms 3352 KB Output is correct
8 Correct 33 ms 5484 KB Output is correct
9 Correct 43 ms 5484 KB Output is correct
10 Correct 14 ms 3328 KB Output is correct
11 Correct 14 ms 3328 KB Output is correct
12 Correct 14 ms 3328 KB Output is correct
13 Correct 13 ms 3328 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 13 ms 3328 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Incorrect 16 ms 3328 KB Output isn't correct
20 Halted 0 ms 0 KB -