# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
880530 |
2023-11-29T15:30:00 Z |
cpptowin |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
7 ms |
10800 KB |
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 100010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf 1000000000
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1 << j))
#define onbit(i, j) (i | (1 << j))
#define vi vector<int>
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
string s;
int cnt[maxn][3];
int n;
int ans = inf;
int k;
int f[maxn][3];
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k >> s;
s = ' ' + s;
memset(f, -1, sizeof f);
fo(i, 1, n)
{
fo(j, 0, 2) cnt[i][j] = cnt[i - 1][j];
if (s[i] == 'J')
cnt[i][0]++;
if (s[i] == 'O')
cnt[i][1]++;
if (s[i] == 'I')
cnt[i][2]++;
if (f[cnt[i][0]][0] == -1)
f[cnt[i][0]][0] = i;
if (f[cnt[i][1]][1] == -1)
f[cnt[i][1]][1] = i;
if (f[cnt[i][2]][2] == -1)
f[cnt[i][2]][2] = i;
}
// fo(i, 1, n) cout << cnt[i][0] << ' ' << cnt[i][1] << ' ' << cnt[i][2] << "\n";
fo(i, 0, n)
{
// cout << i << "\n";
int val = cnt[i][0];
int pos = f[val + k][0];
if (pos == -1)
break;
int now = 0;
now += cnt[pos][1] - cnt[i][1] + cnt[pos][2] - cnt[i][2];
val = cnt[pos][1];
int pre = pos;
pos = f[val + k][1];
if (pos == -1)
break;
now += cnt[pos][2] - cnt[pre][2] + cnt[pos][0] - cnt[pre][0];
// cout << now << ' ' << pos << "\n";
pre = pos;
val = cnt[pos][2];
pos = f[val + k][2];
if (pos == -1)
break;
now += cnt[pos][1] - cnt[pre][1] + cnt[pos][0] - cnt[pre][0];
// cout << now << ' ' << pos << "\n";
ans = min(ans, now);
// cout << ans << "\n";
// cout << now << "\n";
}
cout << (ans == inf ? -1 : ans);
}
Compilation message
ho_t2.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main()
| ^~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | freopen(name ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4528 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4528 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4556 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
1 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4560 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4560 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4752 KB |
Output is correct |
32 |
Correct |
1 ms |
4852 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4528 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4556 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
1 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4560 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4560 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4752 KB |
Output is correct |
32 |
Correct |
1 ms |
4852 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
1 ms |
4700 KB |
Output is correct |
36 |
Runtime error |
7 ms |
10800 KB |
Execution killed with signal 11 |
37 |
Halted |
0 ms |
0 KB |
- |