# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
149222 |
2019-09-01T06:00:16 Z |
shdut0901(#3758, shdut) |
HicCup (FXCUP4_hiccup) |
C++17 |
|
48 ms |
11148 KB |
#include "hiccup.h"
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include <assert.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b - 1; i >= a; i--)
#define ll long long
#define x first
#define y second
#define vi vector<int>
#define pii pair<int, int>
#define SZ(x) (int)(x.size())
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define inf 1000000007
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define N 100005
template<typename U, typename V> void Min(U &a, const V &b){if(a > b) a = b;}
template<typename U, typename V> void Max(U &a, const V &b){if(a < b) a = b;}
template<typename U, typename V> void add(U &a, const V &b){a = (a+b) % mod;}
int get(char c){
if(c == 'H')return 0;
else if(c == 'C')return 1;
else return 2;
}
int HicCup(std::string s) {
int n = s.size();
vi from(n), q(n);
int a[3] = {0};
rep(i, 0, n){
a[get(s[i])]++;
}
if(a[0] != a[1] || a[0] == 0)return -1;
if(get(s[0]) != 0)return -1;
int m = 0, k, last = -1, pos;
int r = a[2] / a[0];
int l = 0;
rep(i, 0, n){
k = get(s[i]);
if(k == 0){
q[m++] = i;
if(last == 0 && pos != i - 1)return -1;
last = 0, pos = i;
}
else if(k == 1){
if(m == 0)return -1;
if(last == 0 && q[m-1] != i-1)return -1;
else if(last == 1){
Min(r, i - pos - 1);
}
m--;
last = 1, pos = i;
}
}
if(m)return -1;
while(l <= r){
m = (l + r) >> 1;
int rem = 0, ok = 1;
per(i, 0, n){
k = get(s[i]);
if(k == 2)rem++;
else if(k == 1){
if(rem < m){ok = 0;break;}
rem -= m;
}
}
if(ok)l = m + 1;
else r = m - 1;
}
l--;
return l;
}
Compilation message
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:57:17: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(last == 0 && pos != i - 1)return -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 |
896 KB |
Output is correct |
5 |
Correct |
37 ms |
11136 KB |
Output is correct |
6 |
Correct |
24 ms |
11136 KB |
Output is correct |
7 |
Correct |
24 ms |
11136 KB |
Output is correct |
8 |
Correct |
37 ms |
11008 KB |
Output is correct |
9 |
Correct |
40 ms |
11136 KB |
Output is correct |
10 |
Correct |
25 ms |
11148 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 |
896 KB |
Output is correct |
5 |
Correct |
37 ms |
11136 KB |
Output is correct |
6 |
Correct |
24 ms |
11136 KB |
Output is correct |
7 |
Correct |
24 ms |
11136 KB |
Output is correct |
8 |
Correct |
37 ms |
11008 KB |
Output is correct |
9 |
Correct |
40 ms |
11136 KB |
Output is correct |
10 |
Correct |
25 ms |
11148 KB |
Output is correct |
11 |
Correct |
25 ms |
11136 KB |
Output is correct |
12 |
Correct |
23 ms |
11136 KB |
Output is correct |
13 |
Correct |
22 ms |
11108 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
23 ms |
11136 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
1152 KB |
Output is correct |
19 |
Correct |
28 ms |
11144 KB |
Output is correct |
20 |
Correct |
28 ms |
11136 KB |
Output is correct |
21 |
Correct |
30 ms |
11136 KB |
Output is correct |
22 |
Correct |
42 ms |
10624 KB |
Output is correct |
23 |
Correct |
45 ms |
11136 KB |
Output is correct |
24 |
Correct |
28 ms |
11136 KB |
Output is correct |
25 |
Correct |
37 ms |
11136 KB |
Output is correct |
26 |
Correct |
32 ms |
11136 KB |
Output is correct |
27 |
Correct |
29 ms |
11136 KB |
Output is correct |
28 |
Correct |
36 ms |
10880 KB |
Output is correct |
29 |
Correct |
48 ms |
11136 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
7 ms |
1280 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |