답안 #229252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229252 2020-05-03T23:29:24 Z 534351 HicCup (FXCUP4_hiccup) C++17
100 / 100
74 ms 42872 KB
#include "hiccup.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 1000013;

int N, M, K;
pii pos[MAXN];
int val[MAXN];
int parent[MAXN];
int freq[MAXN];
vi edge[MAXN];
int ans = MAXN;

void proc(int u)
{
    int c = 0, n = 0;
    for (int v : edge[u])
    {
        c += freq[v];
        n++;
        ckmin(ans, c / n);
    }
}
int HicCup(string str)
{
    N = SZ(str);
	if (str[0] == '!') return -1;
    vi stk; stk.PB(N);
    FORD(i, N, 0)
    {
        char c = str[i];
        if (c == '!')
        {
            if (str[i - 1] == 'H')
            {
                return -1;
            }
            K++;
        }
        else if (c == 'H')
        {
            if (stk.empty()) return -1;
            val[i] = stk.back();
            stk.pop_back();
            if (stk.empty()) return -1;
            parent[val[i]] = stk.back();
            edge[parent[val[i]]].PB(val[i]);
            // cerr << "edge " << parent[val[i]] << " - > " << val[i] << endl;
            K = 0;
        }
        else if (c == 'C')
        {
            val[i] = M;
            M++;
            stk.PB(val[i]);
            freq[val[i]] = K;
            // cerr << val[i] << " has " << K << endl;
            K = 0;
        }
        else return -1;
    }
    if (SZ(stk) != 1 || stk[0] != N)
    {
        return -1;
    }
    FOR(i, 0, M)
    {
        proc(i);
    }
    proc(N);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 19 ms 24576 KB Output is correct
5 Correct 72 ms 42872 KB Output is correct
6 Correct 24 ms 26880 KB Output is correct
7 Correct 23 ms 26880 KB Output is correct
8 Correct 71 ms 42872 KB Output is correct
9 Correct 74 ms 42872 KB Output is correct
10 Correct 24 ms 26880 KB Output is correct
11 Correct 17 ms 23776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 19 ms 24576 KB Output is correct
5 Correct 72 ms 42872 KB Output is correct
6 Correct 24 ms 26880 KB Output is correct
7 Correct 23 ms 26880 KB Output is correct
8 Correct 71 ms 42872 KB Output is correct
9 Correct 74 ms 42872 KB Output is correct
10 Correct 24 ms 26880 KB Output is correct
11 Correct 25 ms 27128 KB Output is correct
12 Correct 25 ms 27776 KB Output is correct
13 Correct 27 ms 28280 KB Output is correct
14 Correct 18 ms 23936 KB Output is correct
15 Correct 29 ms 30976 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 18 ms 23808 KB Output is correct
18 Correct 18 ms 24192 KB Output is correct
19 Correct 28 ms 30848 KB Output is correct
20 Correct 29 ms 30976 KB Output is correct
21 Correct 28 ms 29440 KB Output is correct
22 Correct 26 ms 27648 KB Output is correct
23 Correct 28 ms 27776 KB Output is correct
24 Correct 29 ms 32000 KB Output is correct
25 Correct 57 ms 39036 KB Output is correct
26 Correct 33 ms 33272 KB Output is correct
27 Correct 28 ms 29824 KB Output is correct
28 Correct 30 ms 28152 KB Output is correct
29 Correct 27 ms 27776 KB Output is correct
30 Correct 18 ms 23808 KB Output is correct
31 Correct 17 ms 23808 KB Output is correct
32 Correct 19 ms 24192 KB Output is correct
33 Correct 17 ms 23776 KB Output is correct