# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
149993 |
2019-09-01T07:30:49 Z |
Avengers(#3759, Blagojce) |
HicCup (FXCUP4_hiccup) |
C++17 |
|
86 ms |
38780 KB |
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
#include "hiccup.h"
vector<int> nums[1000006];
bool ok(int x, int id){
int c = 0;
for(auto u : nums[id]){
if(u > x){
if(u - x >= c) c = 0;
else{
c -= (u - x);
}
}
else{
c += (x - u);
}
}
return c == 0;
}
int HicCup(std::string s) {
int n = s.size();
int cnt[n];
int c = 0;
for(int i = n - 1; i >= 0; i --){
if(s[i] == '!') c ++;
cnt[i] = c;
if(s[i] == 'C') c = 0;
else if(s[i] == 'H' && c > 0) return -1;
}
if(c > 0) return -1;
stack <int> S;
S.push(0);
int ANS = n;
fr(i, 0, n){
if(s[i] == 'H') S.push(i + 1);
else if(s[i] == 'C'){
if((int)(S.size()) == 1) return -1;
int id = S.top();
S.pop();
nums[(int)S.top()].pb(cnt[i]);
if(nums[id].empty()) continue;
int k = 0;
for(int b = ANS / 2; b >= 1; b /= 2){
while(k + b <= ANS && ok(k + b, id)) k += b;
}
ANS = min(ANS, k);
}
}
if((int)S.size() > 1)return -1;
if(!nums[0].empty()){
int k = 0;
for(int b = ANS / 2; b >= 1; b /= 2){
while(k + b <= ANS && ok(k + b, 0)) k += b;
}
ANS = min(ANS, k);
}
return ANS;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23856 KB |
Output is correct |
2 |
Correct |
36 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23808 KB |
Output is correct |
4 |
Correct |
23 ms |
24448 KB |
Output is correct |
5 |
Correct |
77 ms |
38780 KB |
Output is correct |
6 |
Correct |
37 ms |
30712 KB |
Output is correct |
7 |
Correct |
38 ms |
30720 KB |
Output is correct |
8 |
Correct |
80 ms |
38776 KB |
Output is correct |
9 |
Correct |
86 ms |
38648 KB |
Output is correct |
10 |
Correct |
38 ms |
30712 KB |
Output is correct |
11 |
Correct |
21 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23856 KB |
Output is correct |
2 |
Correct |
36 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23808 KB |
Output is correct |
4 |
Correct |
23 ms |
24448 KB |
Output is correct |
5 |
Correct |
77 ms |
38780 KB |
Output is correct |
6 |
Correct |
37 ms |
30712 KB |
Output is correct |
7 |
Correct |
38 ms |
30720 KB |
Output is correct |
8 |
Correct |
80 ms |
38776 KB |
Output is correct |
9 |
Correct |
86 ms |
38648 KB |
Output is correct |
10 |
Correct |
38 ms |
30712 KB |
Output is correct |
11 |
Correct |
29 ms |
26880 KB |
Output is correct |
12 |
Correct |
27 ms |
27256 KB |
Output is correct |
13 |
Correct |
31 ms |
29440 KB |
Output is correct |
14 |
Correct |
18 ms |
23808 KB |
Output is correct |
15 |
Correct |
35 ms |
30456 KB |
Output is correct |
16 |
Correct |
24 ms |
23808 KB |
Output is correct |
17 |
Correct |
23 ms |
23808 KB |
Output is correct |
18 |
Correct |
23 ms |
24064 KB |
Output is correct |
19 |
Correct |
32 ms |
30720 KB |
Output is correct |
20 |
Correct |
35 ms |
30848 KB |
Output is correct |
21 |
Correct |
32 ms |
30712 KB |
Output is correct |
22 |
Correct |
29 ms |
30336 KB |
Output is correct |
23 |
Correct |
32 ms |
30712 KB |
Output is correct |
24 |
Correct |
35 ms |
30968 KB |
Output is correct |
25 |
Correct |
63 ms |
35064 KB |
Output is correct |
26 |
Correct |
48 ms |
31480 KB |
Output is correct |
27 |
Correct |
34 ms |
30712 KB |
Output is correct |
28 |
Correct |
33 ms |
30584 KB |
Output is correct |
29 |
Correct |
34 ms |
30584 KB |
Output is correct |
30 |
Correct |
22 ms |
23808 KB |
Output is correct |
31 |
Incorrect |
22 ms |
23808 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |