# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
149750 | | Avengers (#200) | HicCup (FXCUP4_hiccup) | C++17 | | 40 ms | 15104 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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"
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 sums[n + 1];
int nums[n + 1];
memset(sums, 0, sizeof(sums));
memset(nums, 0, sizeof(nums));
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();
sums[(int)S.top()] += cnt[i];
nums[(int)S.top()] ++;
if(nums[id] > 0) ANS = min(ANS, sums[id] / nums[id]);
}
}
if((int)S.size() > 1)return -1;
if(nums[0] > 0)ANS = min(ANS, sums[0] / nums[0]);
return ANS;
}
/*
int main()
{
cout << HicCup("HC!!HHC!HC!!!C!!!");
return 0;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |