Submission #150170

# Submission time Handle Problem Language Result Execution time Memory
150170 2019-09-01T07:50:22 Z graneli(#3789, toloraia) HicCup (FXCUP4_hiccup) C++17
100 / 100
174 ms 5668 KB
#include "hiccup.h"
#include <bits/stdc++.h>
#define F first
//#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
using namespace std;

const int N = 1000005;

int n;
int x, y, z;
string s;
string S;
stack < int > St;

bool check (int num){
    while (St.size() > 0)
        St.pop();
    s = "#HC";
    for (int i = 0; i < num; i++)
        s += "!";
    int m = num + 2;
    bool ok = 0;
    for (int i = 1; i <= n; i++){
        if (S[i] == 'H')
            St.push (0);
        if (S[i] == 'H')
            ok = 0;
        if (S[i] == 'C')
            ok = 1;
        if (St.size() == 0 && S[i] == 'C')
            return 0;
        if (St.size() == 0 && ok == 0)
            return 0;
        if (St.size() == 0)
            continue;
        x = St.top() + 1;
        if (S[i] != s[x]){
            if (S[i] != '!' || ok == 0)
                return 0;
            continue;
        }
        St.pop();
        if (x < m)
            St.push (x);
    }
    if (St.size() == 0)
        return 1;
    return 0;
}


int HicCup(string str) {
    S = str;
	n = (int)S.size();
	S = "#" + S;
	for (int i = 1; i <= n; i++){
        if (S[i] == 'H')
            x++;
        else if (S[i] == 'C')
            y++;
        else
            z++;
	}
	if (x != y)
        return -1;
    int l = -1, r = z / x;
    while (l < r){
        int mid = l + r + 1 >> 1;
        if (check (mid))
            l = mid;
        else
            r = mid - 1;
    }
    /*bool ok = check (0);
    if (ok == 0)
        return -1;*/
    return l;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:78:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r + 1 >> 1;
                   ~~~~~~^~~
# 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 5 ms 384 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 30 ms 5248 KB Output is correct
6 Correct 22 ms 5248 KB Output is correct
7 Correct 20 ms 5120 KB Output is correct
8 Correct 31 ms 5248 KB Output is correct
9 Correct 32 ms 5248 KB Output is correct
10 Correct 28 ms 5280 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 5 ms 384 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 30 ms 5248 KB Output is correct
6 Correct 22 ms 5248 KB Output is correct
7 Correct 20 ms 5120 KB Output is correct
8 Correct 31 ms 5248 KB Output is correct
9 Correct 32 ms 5248 KB Output is correct
10 Correct 28 ms 5280 KB Output is correct
11 Correct 23 ms 5248 KB Output is correct
12 Correct 22 ms 5248 KB Output is correct
13 Correct 21 ms 5248 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 18 ms 5248 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 45 ms 5248 KB Output is correct
20 Correct 47 ms 5248 KB Output is correct
21 Correct 48 ms 5248 KB Output is correct
22 Correct 112 ms 4992 KB Output is correct
23 Correct 174 ms 5668 KB Output is correct
24 Correct 25 ms 5248 KB Output is correct
25 Correct 31 ms 5120 KB Output is correct
26 Correct 56 ms 5120 KB Output is correct
27 Correct 60 ms 5248 KB Output is correct
28 Correct 75 ms 5120 KB Output is correct
29 Correct 102 ms 5248 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 128 KB Output is correct
32 Correct 10 ms 768 KB Output is correct
33 Correct 5 ms 384 KB Output is correct