# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
880531 |
2023-11-29T15:30:24 Z |
cpptowin |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
9 ms |
29884 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 1000010
#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 |
3 ms |
25432 KB |
Output is correct |
2 |
Correct |
4 ms |
25192 KB |
Output is correct |
3 |
Correct |
3 ms |
25180 KB |
Output is correct |
4 |
Correct |
4 ms |
25180 KB |
Output is correct |
5 |
Correct |
3 ms |
25176 KB |
Output is correct |
6 |
Correct |
3 ms |
25180 KB |
Output is correct |
7 |
Correct |
3 ms |
25256 KB |
Output is correct |
8 |
Correct |
3 ms |
25176 KB |
Output is correct |
9 |
Correct |
3 ms |
25176 KB |
Output is correct |
10 |
Correct |
3 ms |
25180 KB |
Output is correct |
11 |
Correct |
3 ms |
25432 KB |
Output is correct |
12 |
Correct |
3 ms |
25180 KB |
Output is correct |
13 |
Correct |
3 ms |
25176 KB |
Output is correct |
14 |
Correct |
3 ms |
25180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
25432 KB |
Output is correct |
2 |
Correct |
4 ms |
25192 KB |
Output is correct |
3 |
Correct |
3 ms |
25180 KB |
Output is correct |
4 |
Correct |
4 ms |
25180 KB |
Output is correct |
5 |
Correct |
3 ms |
25176 KB |
Output is correct |
6 |
Correct |
3 ms |
25180 KB |
Output is correct |
7 |
Correct |
3 ms |
25256 KB |
Output is correct |
8 |
Correct |
3 ms |
25176 KB |
Output is correct |
9 |
Correct |
3 ms |
25176 KB |
Output is correct |
10 |
Correct |
3 ms |
25180 KB |
Output is correct |
11 |
Correct |
3 ms |
25432 KB |
Output is correct |
12 |
Correct |
3 ms |
25180 KB |
Output is correct |
13 |
Correct |
3 ms |
25176 KB |
Output is correct |
14 |
Correct |
3 ms |
25180 KB |
Output is correct |
15 |
Correct |
4 ms |
25180 KB |
Output is correct |
16 |
Correct |
4 ms |
25180 KB |
Output is correct |
17 |
Correct |
3 ms |
25180 KB |
Output is correct |
18 |
Correct |
3 ms |
25180 KB |
Output is correct |
19 |
Correct |
3 ms |
25180 KB |
Output is correct |
20 |
Correct |
3 ms |
25180 KB |
Output is correct |
21 |
Correct |
3 ms |
25180 KB |
Output is correct |
22 |
Correct |
4 ms |
25180 KB |
Output is correct |
23 |
Correct |
4 ms |
25180 KB |
Output is correct |
24 |
Correct |
3 ms |
25180 KB |
Output is correct |
25 |
Correct |
4 ms |
25180 KB |
Output is correct |
26 |
Correct |
3 ms |
25180 KB |
Output is correct |
27 |
Correct |
3 ms |
25180 KB |
Output is correct |
28 |
Correct |
3 ms |
25180 KB |
Output is correct |
29 |
Correct |
3 ms |
25180 KB |
Output is correct |
30 |
Correct |
3 ms |
25180 KB |
Output is correct |
31 |
Correct |
4 ms |
25176 KB |
Output is correct |
32 |
Correct |
3 ms |
25180 KB |
Output is correct |
33 |
Correct |
3 ms |
25176 KB |
Output is correct |
34 |
Correct |
3 ms |
25180 KB |
Output is correct |
35 |
Correct |
3 ms |
25180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
25432 KB |
Output is correct |
2 |
Correct |
4 ms |
25192 KB |
Output is correct |
3 |
Correct |
3 ms |
25180 KB |
Output is correct |
4 |
Correct |
4 ms |
25180 KB |
Output is correct |
5 |
Correct |
3 ms |
25176 KB |
Output is correct |
6 |
Correct |
3 ms |
25180 KB |
Output is correct |
7 |
Correct |
3 ms |
25256 KB |
Output is correct |
8 |
Correct |
3 ms |
25176 KB |
Output is correct |
9 |
Correct |
3 ms |
25176 KB |
Output is correct |
10 |
Correct |
3 ms |
25180 KB |
Output is correct |
11 |
Correct |
3 ms |
25432 KB |
Output is correct |
12 |
Correct |
3 ms |
25180 KB |
Output is correct |
13 |
Correct |
3 ms |
25176 KB |
Output is correct |
14 |
Correct |
3 ms |
25180 KB |
Output is correct |
15 |
Correct |
4 ms |
25180 KB |
Output is correct |
16 |
Correct |
4 ms |
25180 KB |
Output is correct |
17 |
Correct |
3 ms |
25180 KB |
Output is correct |
18 |
Correct |
3 ms |
25180 KB |
Output is correct |
19 |
Correct |
3 ms |
25180 KB |
Output is correct |
20 |
Correct |
3 ms |
25180 KB |
Output is correct |
21 |
Correct |
3 ms |
25180 KB |
Output is correct |
22 |
Correct |
4 ms |
25180 KB |
Output is correct |
23 |
Correct |
4 ms |
25180 KB |
Output is correct |
24 |
Correct |
3 ms |
25180 KB |
Output is correct |
25 |
Correct |
4 ms |
25180 KB |
Output is correct |
26 |
Correct |
3 ms |
25180 KB |
Output is correct |
27 |
Correct |
3 ms |
25180 KB |
Output is correct |
28 |
Correct |
3 ms |
25180 KB |
Output is correct |
29 |
Correct |
3 ms |
25180 KB |
Output is correct |
30 |
Correct |
3 ms |
25180 KB |
Output is correct |
31 |
Correct |
4 ms |
25176 KB |
Output is correct |
32 |
Correct |
3 ms |
25180 KB |
Output is correct |
33 |
Correct |
3 ms |
25176 KB |
Output is correct |
34 |
Correct |
3 ms |
25180 KB |
Output is correct |
35 |
Correct |
3 ms |
25180 KB |
Output is correct |
36 |
Correct |
8 ms |
29488 KB |
Output is correct |
37 |
Correct |
9 ms |
29732 KB |
Output is correct |
38 |
Correct |
7 ms |
29732 KB |
Output is correct |
39 |
Correct |
7 ms |
29860 KB |
Output is correct |
40 |
Correct |
6 ms |
29732 KB |
Output is correct |
41 |
Correct |
8 ms |
29728 KB |
Output is correct |
42 |
Correct |
8 ms |
29732 KB |
Output is correct |
43 |
Correct |
5 ms |
27740 KB |
Output is correct |
44 |
Correct |
6 ms |
29792 KB |
Output is correct |
45 |
Correct |
9 ms |
29840 KB |
Output is correct |
46 |
Correct |
7 ms |
29732 KB |
Output is correct |
47 |
Correct |
6 ms |
29732 KB |
Output is correct |
48 |
Correct |
6 ms |
29864 KB |
Output is correct |
49 |
Correct |
5 ms |
27664 KB |
Output is correct |
50 |
Correct |
6 ms |
29884 KB |
Output is correct |
51 |
Correct |
6 ms |
29732 KB |
Output is correct |
52 |
Correct |
6 ms |
29740 KB |
Output is correct |
53 |
Correct |
6 ms |
29732 KB |
Output is correct |
54 |
Correct |
6 ms |
29884 KB |
Output is correct |
55 |
Correct |
5 ms |
29728 KB |
Output is correct |
56 |
Correct |
5 ms |
29732 KB |
Output is correct |