Submission #201027

# Submission time Handle Problem Language Result Execution time Memory
201027 2020-02-09T06:26:25 Z gs14004 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
19 ms 6008 KB
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 200005;

int n, l;
char str[MAXN];
int dp[4][MAXN];
int sum[4][MAXN];

int main(){
	scanf("%d %d %s",&n,&l,str + 1);
	for(int i=1; i<=n; i++){
		if(str[i] == 'J') sum[1][i]++;
		if(str[i] == 'O') sum[2][i]++;
		if(str[i] == 'I') sum[3][i]++;
		for(int j=0; j<4; j++){
			sum[j][i] += sum[j][i-1];
		}
	}
	for(int i=1; i<=3; i++){
		memset(dp[i], 0x3f, sizeof(dp[i]));
		int ptr = 0;
		int cur = 1e9;
		for(int j=1; j<=n; j++){
			while(ptr < j && sum[i][j] - sum[i][ptr] >= l){
				cur = min(cur, dp[i-1][ptr] - ptr);
				ptr++;
			}
			dp[i][j] = cur + j;
		}
	}
	int ans= *min_element(dp[3], dp[3] + n + 1) - 3 * l;
	if(ans > 1e7) ans = -1;
	cout << ans << endl;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %s",&n,&l,str + 1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 7 ms 2684 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 7 ms 2680 KB Output is correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 7 ms 2684 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 7 ms 2680 KB Output is correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 8 ms 2808 KB Output is correct
16 Correct 7 ms 2680 KB Output is correct
17 Correct 7 ms 2808 KB Output is correct
18 Correct 7 ms 2680 KB Output is correct
19 Correct 7 ms 2808 KB Output is correct
20 Correct 7 ms 2808 KB Output is correct
21 Correct 6 ms 2680 KB Output is correct
22 Correct 6 ms 2680 KB Output is correct
23 Correct 6 ms 2680 KB Output is correct
24 Correct 7 ms 2808 KB Output is correct
25 Correct 6 ms 2808 KB Output is correct
26 Correct 7 ms 2680 KB Output is correct
27 Correct 7 ms 2680 KB Output is correct
28 Correct 6 ms 2808 KB Output is correct
29 Correct 7 ms 2808 KB Output is correct
30 Correct 6 ms 2680 KB Output is correct
31 Correct 6 ms 2680 KB Output is correct
32 Correct 6 ms 2680 KB Output is correct
33 Correct 11 ms 2680 KB Output is correct
34 Correct 6 ms 2680 KB Output is correct
35 Correct 6 ms 2684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 7 ms 2684 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2680 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 7 ms 2680 KB Output is correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 8 ms 2808 KB Output is correct
16 Correct 7 ms 2680 KB Output is correct
17 Correct 7 ms 2808 KB Output is correct
18 Correct 7 ms 2680 KB Output is correct
19 Correct 7 ms 2808 KB Output is correct
20 Correct 7 ms 2808 KB Output is correct
21 Correct 6 ms 2680 KB Output is correct
22 Correct 6 ms 2680 KB Output is correct
23 Correct 6 ms 2680 KB Output is correct
24 Correct 7 ms 2808 KB Output is correct
25 Correct 6 ms 2808 KB Output is correct
26 Correct 7 ms 2680 KB Output is correct
27 Correct 7 ms 2680 KB Output is correct
28 Correct 6 ms 2808 KB Output is correct
29 Correct 7 ms 2808 KB Output is correct
30 Correct 6 ms 2680 KB Output is correct
31 Correct 6 ms 2680 KB Output is correct
32 Correct 6 ms 2680 KB Output is correct
33 Correct 11 ms 2680 KB Output is correct
34 Correct 6 ms 2680 KB Output is correct
35 Correct 6 ms 2684 KB Output is correct
36 Correct 14 ms 5752 KB Output is correct
37 Correct 18 ms 6008 KB Output is correct
38 Correct 19 ms 6008 KB Output is correct
39 Correct 17 ms 6008 KB Output is correct
40 Correct 16 ms 5932 KB Output is correct
41 Correct 17 ms 6008 KB Output is correct
42 Correct 17 ms 6008 KB Output is correct
43 Correct 12 ms 4728 KB Output is correct
44 Correct 13 ms 5244 KB Output is correct
45 Correct 16 ms 5932 KB Output is correct
46 Correct 15 ms 5984 KB Output is correct
47 Correct 16 ms 6008 KB Output is correct
48 Correct 15 ms 6008 KB Output is correct
49 Correct 12 ms 4856 KB Output is correct
50 Correct 18 ms 6008 KB Output is correct
51 Correct 16 ms 6008 KB Output is correct
52 Correct 13 ms 5880 KB Output is correct
53 Correct 15 ms 6008 KB Output is correct
54 Correct 10 ms 6008 KB Output is correct
55 Correct 11 ms 6008 KB Output is correct
56 Correct 10 ms 6008 KB Output is correct