# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
515957 |
2022-01-20T08:00:16 Z |
David_M |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
1 ms |
336 KB |
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e18, P=998244353;
ll q=1, n, m, x, y, z, l, r, c, k, a[N], b[3][N], f[N], ansl, ansr, ans, o, u, Ans[N];
vector <ll> v[3];
string s;
void solve(){
cin>>n>>k>>s;
for (int i=0; i<n; i++){
a[i]=(s[i]=='J')?0:((s[i]=='O')?1:2);
v[a[i]].pb(i);
}
v[1].pb(INF);
v[2].pb(2*INF);
ans=INF;
for (int x0=0; x0+k-1<v[0].size(); x0++){
int x1=0, x2=0;
while(v[1][x1]<v[0][x0+k-1])x1++;
while(v[2][x2]<v[1][x1+k-1])x2++;
ans=min(ans, v[2][min(x2+k,(ll)v[2].size())-1]-v[0][x0]+1-3*k);
}
cout<<(ans>n?-1:ans);
}
main(){ios_base::sync_with_stdio(false), cin.tie(0);
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message
ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:26:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int x0=0; x0+k-1<v[0].size(); x0++){
| ~~~~~~^~~~~~~~~~~~
ho_t2.cpp: At global scope:
ho_t2.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
38 | main(){ios_base::sync_with_stdio(false), cin.tie(0);
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |