# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
228488 | 2020-05-01T08:34:12 Z | Ruxandra985 | JJOOII 2 (JOI20_ho_t2) | C++14 | 38 ms | 6380 KB |
#include <bits/stdc++.h> #define DIMN 200010 using namespace std; char s[DIMN]; int fi[DIMN] , fj[DIMN] , fo[DIMN]; vector <pair <int,int> > vi , vj; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , k , i , st , dr , mid , j , sol; fscanf (fin,"%d%d\n",&n,&k); fgets (s + 1 , n + 10 , fin); for (i = 1 ; i <= n ; i++){ fj[i] = fj[i - 1]; fo[i] = fo[i - 1]; fi[i] = fi[i - 1]; if (s[i] == 'J') fj[i]++; else if (s[i] == 'O') fo[i]++; else fi[i]++; } sol = n; for (i = 1 ; i <= n ; i++){ st = i; dr = n; while (st <= dr){ mid = (st + dr)/2; if (fj[mid] - fj[i - 1] >= k) dr = mid - 1; else st = mid + 1; } if (st <= n) vj.push_back(make_pair(st , st - i + 1 - k)); /// -------------------------------------------------------------------- /// -------------------------------------------------------------------- st = i; dr = n; while (st <= dr){ mid = (st + dr)/2; if (fi[mid] - fi[i - 1] >= k) dr = mid - 1; else st = mid + 1; } if (st <= n) vi.push_back(make_pair( i , st - i + 1 - k )); } /// vj si vi sunt in ordine crescatoare j = 0; for (i = 0 ; i < vj.size() ; i++){ while (j < vi.size() && fo[vi[j].first - 1] - fo[vj[i].first] < k) j++; if (j == vi.size()) break; //printf ("%d %d\n" , vi[j].first - 1 , vj[i].first + 1); sol = min(sol , vi[j].second + vj[i].second + vi[j].first - 1 - vj[i].first - k); } if (sol == n) sol = -1; fprintf (fout,"%d",sol); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 512 KB | Output is correct |
16 | Correct | 5 ms | 512 KB | Output is correct |
17 | Correct | 5 ms | 512 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 512 KB | Output is correct |
20 | Correct | 5 ms | 512 KB | Output is correct |
21 | Correct | 5 ms | 512 KB | Output is correct |
22 | Correct | 5 ms | 512 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 5 ms | 512 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 384 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 4 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 512 KB | Output is correct |
16 | Correct | 5 ms | 512 KB | Output is correct |
17 | Correct | 5 ms | 512 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 512 KB | Output is correct |
20 | Correct | 5 ms | 512 KB | Output is correct |
21 | Correct | 5 ms | 512 KB | Output is correct |
22 | Correct | 5 ms | 512 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 5 ms | 512 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 384 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 4 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
36 | Correct | 29 ms | 6252 KB | Output is correct |
37 | Correct | 31 ms | 6380 KB | Output is correct |
38 | Correct | 31 ms | 6380 KB | Output is correct |
39 | Correct | 34 ms | 6372 KB | Output is correct |
40 | Correct | 31 ms | 6380 KB | Output is correct |
41 | Correct | 38 ms | 6372 KB | Output is correct |
42 | Correct | 35 ms | 6380 KB | Output is correct |
43 | Correct | 20 ms | 3828 KB | Output is correct |
44 | Correct | 24 ms | 4332 KB | Output is correct |
45 | Correct | 30 ms | 6380 KB | Output is correct |
46 | Correct | 30 ms | 6380 KB | Output is correct |
47 | Correct | 31 ms | 6380 KB | Output is correct |
48 | Correct | 30 ms | 6312 KB | Output is correct |
49 | Correct | 21 ms | 3956 KB | Output is correct |
50 | Correct | 30 ms | 6380 KB | Output is correct |
51 | Correct | 30 ms | 6372 KB | Output is correct |
52 | Correct | 21 ms | 3580 KB | Output is correct |
53 | Correct | 24 ms | 4092 KB | Output is correct |
54 | Correct | 27 ms | 5868 KB | Output is correct |
55 | Correct | 26 ms | 5492 KB | Output is correct |
56 | Correct | 21 ms | 5236 KB | Output is correct |