#include<bits/stdc++.h>
#include<chrono>
using namespace std;
using namespace chrono;
#define all(a) a.begin(), a.end()
#define sz(x) (int(x.size()))
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef vector<string> vs;
template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
in >> P.first >> P.second;
return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
out << "(" << P.first << ", " << P.second << ")";
return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
for(auto &x: arr) in >> x;
return in;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
for(auto &x: arr) out << x << ' '; cout << "\n";
return out;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
for(auto &x: arr) in >> x;
return in;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
for(auto &x: arr) out << x << ' '; cout << "\n";
return out;
}
#include"hiccup.h"
bool solve(const string &s, int i, int j, int val, const vi &p){
int cnt = 0;
for(int k = j - 1; k >= i; k --){
if(s[k] == '!'){
cnt ++;
}
else{
if(cnt < val){
return false;
}
cnt -= val;
if(!solve(s, p[k] + 1, k, val, p)){
return false;
}
k = p[k];
}
}
return true;
}
int HicCup(string s){
int n = s.size();
vi p(n, -1);
vi hpos;
for(int i = 0; i < n; i ++){
if(s[i] == 'H'){
hpos.push_back(i);
}
else if(s[i] == 'C'){
if(hpos.empty()){
return -1;
}
p[i] = hpos.back();
p[hpos.back()] = i;
hpos.pop_back();
}
else{
if(!i || s[i - 1] == 'H'){
return -1;
}
}
}
if(!hpos.empty()){
return -1;
}
if(!solve(s, 0, n, 0, p)){
return -1;
}
int l = 0, r = n;
while(r - l > 1){
int m = l + r >> 1;
solve(s, 0, n, m, p) ? l = m : r = m;
}
return l;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// //
// _____________ //
// ++++++++++ ___------------------\\\\ //
// +++`+``+`+`++++ ///`````````````````````````````\\\ //
// ++`+`+``+++`++++ /////```````````````````````````````````\\ //
// +++`++`+`+``+++/////`````````````````````````````````````````\\ //
// +++`++`+``+///```````````|```````````````````````````````````\\ //
// ____++++/++++/`````````````/````````|````````|```````````````````\\ //
// / / / | //``````````````|````````|```````|````````|````````````\\ //
// / / / | ///````````/```````|```````||```````|````````|``````\```````\\ //
// | / / |///`````````|``````/````````|````````|````````|```````|```````\\ //
// |/ | |//``|```````|``````|````````|`````````|```````|```````|````````\\ //
// /\___|__//`|``|```````|` | ``:|````````|:```````|```````|```|`````| //
// / / /``|``|``````|/ | :| ```:|```````|```````|``++````++ //
// / / //```|``|``````| | |: :| ```|```````|```++``++`\ //
// | / /````|``|``````/ _.::::. | | | ````|```|`++`\`| //
// | / |````|``|`````| ` | ``|```++``++`| //
// | / |````|``|`````| : |``++````++| //
// | / /````|``|`````| _.-:::. |..`|``.`|.| //
// |/ /`````|``|`````| ` |```|````|`| //
// /| |`````|``|`````| :' .|```|````|.| //
// / | |`````|``|`````| /|-|``|````|`| //
// / | |`````|```\````| / ||```|````|``\ //
// / | |`````|````|```|:: /_| ||```|````|``| //
// |`````|````|```|:|:. `.._ .\___/:|```|````|``| //
// |`````\````|```|:|::- ``:::.... -:|:|:::|```|````|``| //
// |``````|```|```|:|::`|. .:::|:|:::|```|````|``| //
// \`````|```|```|:|::/|--. .`:|:::|:|:::/```|````|``| //
// |````|```|```\:|:|:|----- _..-:|:|:|:::|:|::|````|````|`/ //
// |````|```|````\|:|:|-------.____.....------|/::|:::|:|::|````|````|`| //
// |````|```|\````\:|/\___________ ________/\--\:::|:|::|````/````|`| //
// |````\```| \```|:/-------------\ /----------\``\::|:|::|```/`````|`| //
// |`````|``| \``|/---------------\/------------\_________|```|`````|`| //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Created by Aeren //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////////
Compilation message
hiccup.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)':
hiccup.cpp:32:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(auto &x: arr) out << x << ' '; cout << "\n";
^~~
hiccup.cpp:32:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(auto &x: arr) out << x << ' '; cout << "\n";
^~~~
hiccup.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::deque<_Tp>&)':
hiccup.cpp:42:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(auto &x: arr) out << x << ' '; cout << "\n";
^~~
hiccup.cpp:42:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(auto &x: arr) out << x << ' '; cout << "\n";
^~~~
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:95:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
35 ms |
7296 KB |
Output is correct |
6 |
Correct |
15 ms |
7296 KB |
Output is correct |
7 |
Correct |
15 ms |
7296 KB |
Output is correct |
8 |
Correct |
35 ms |
7168 KB |
Output is correct |
9 |
Correct |
36 ms |
7296 KB |
Output is correct |
10 |
Correct |
17 ms |
7168 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
35 ms |
7296 KB |
Output is correct |
6 |
Correct |
15 ms |
7296 KB |
Output is correct |
7 |
Correct |
15 ms |
7296 KB |
Output is correct |
8 |
Correct |
35 ms |
7168 KB |
Output is correct |
9 |
Correct |
36 ms |
7296 KB |
Output is correct |
10 |
Correct |
17 ms |
7168 KB |
Output is correct |
11 |
Correct |
19 ms |
7296 KB |
Output is correct |
12 |
Correct |
17 ms |
7296 KB |
Output is correct |
13 |
Correct |
16 ms |
7296 KB |
Output is correct |
14 |
Correct |
12 ms |
384 KB |
Output is correct |
15 |
Correct |
15 ms |
7296 KB |
Output is correct |
16 |
Correct |
6 ms |
336 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
896 KB |
Output is correct |
19 |
Correct |
22 ms |
7040 KB |
Output is correct |
20 |
Correct |
26 ms |
7296 KB |
Output is correct |
21 |
Correct |
31 ms |
7256 KB |
Output is correct |
22 |
Correct |
27 ms |
6912 KB |
Output is correct |
23 |
Correct |
39 ms |
7168 KB |
Output is correct |
24 |
Correct |
24 ms |
7296 KB |
Output is correct |
25 |
Correct |
33 ms |
7168 KB |
Output is correct |
26 |
Correct |
28 ms |
7168 KB |
Output is correct |
27 |
Correct |
24 ms |
7296 KB |
Output is correct |
28 |
Correct |
30 ms |
7040 KB |
Output is correct |
29 |
Correct |
36 ms |
7296 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
7 ms |
896 KB |
Output is correct |
33 |
Correct |
6 ms |
384 KB |
Output is correct |