# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
225707 |
2020-04-21T11:09:04 Z |
Ruxandra985 |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
2688 KB |
#include <bits/stdc++.h>
using namespace std;
int v[1000010] , dp[1000010][2][2] , sol[1000010];
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , m , i , j , k , difj , difk , x;
fscanf (fin,"%d%d",&n,&m);
for (i = 1 ; i <= n ; i++){
fscanf (fin,"%d",&v[i]);
}
for (i = 1 ; i <= m ; i++)
sol[i] = 2000000000 * (m != 1);
for (j = 1 ; j <= m ; j++){
for (k = 1 ; k <= m ; k++){
if (j == k)
continue;
/// pui culoarea j sau k peste tot
/// forma generala :
/// orice , par , par , ... , par , orice
/// dp[i][tip_cul][0 / 1] = cmin pana la i, ai culoarea aia, len % 2 = 0 / 1
dp[1][0][1] = (v[1] != j);
dp[1][1][1] = (v[1] != k);
dp[1][0][0] = dp[1][1][0] = 2000000000;
difj = (v[1] != j);
difk = (v[1] != k);
for (i = 2 ; i <= n ; i++){
dp[i][0][1] = min( dp[i - 1][0][0] , min( difk , dp[i - 1][1][0] ) ) + (v[i] != j);
dp[i][1][1] = min( dp[i - 1][1][0] , min( difj , dp[i - 1][0][0] ) ) + (v[i] != k);
dp[i][0][0] = dp[i - 1][0][1] + (v[i] != j);
dp[i][1][0] = dp[i - 1][1][1] + (v[i] != k);
difj += (v[i] != j);
difk += (v[i] != k);
}
x = min( min( dp[n][0][1] , dp[n][1][1] ) , min( dp[n][0][0] , dp[n][1][0] ) );
sol[j] = min(sol[j] , x);
sol[k] = min(sol[k] , x);
}
}
for (i = 1 ; i <= m ; i++)
fprintf (fout,"%d\n",sol[i]);
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:10:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d%d",&n,&m);
~~~~~~~^~~~~~~~~~~~~~~~~~
rope.cpp:12:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d",&v[i]);
~~~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
64 ms |
2444 KB |
Output is correct |
28 |
Correct |
22 ms |
2560 KB |
Output is correct |
29 |
Correct |
53 ms |
2432 KB |
Output is correct |
30 |
Correct |
26 ms |
2432 KB |
Output is correct |
31 |
Correct |
61 ms |
2432 KB |
Output is correct |
32 |
Correct |
21 ms |
2432 KB |
Output is correct |
33 |
Correct |
59 ms |
2432 KB |
Output is correct |
34 |
Correct |
26 ms |
2544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
64 ms |
2444 KB |
Output is correct |
28 |
Correct |
22 ms |
2560 KB |
Output is correct |
29 |
Correct |
53 ms |
2432 KB |
Output is correct |
30 |
Correct |
26 ms |
2432 KB |
Output is correct |
31 |
Correct |
61 ms |
2432 KB |
Output is correct |
32 |
Correct |
21 ms |
2432 KB |
Output is correct |
33 |
Correct |
59 ms |
2432 KB |
Output is correct |
34 |
Correct |
26 ms |
2544 KB |
Output is correct |
35 |
Execution timed out |
2587 ms |
2688 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
64 ms |
2444 KB |
Output is correct |
28 |
Correct |
22 ms |
2560 KB |
Output is correct |
29 |
Correct |
53 ms |
2432 KB |
Output is correct |
30 |
Correct |
26 ms |
2432 KB |
Output is correct |
31 |
Correct |
61 ms |
2432 KB |
Output is correct |
32 |
Correct |
21 ms |
2432 KB |
Output is correct |
33 |
Correct |
59 ms |
2432 KB |
Output is correct |
34 |
Correct |
26 ms |
2544 KB |
Output is correct |
35 |
Execution timed out |
2587 ms |
2688 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
64 ms |
2444 KB |
Output is correct |
28 |
Correct |
22 ms |
2560 KB |
Output is correct |
29 |
Correct |
53 ms |
2432 KB |
Output is correct |
30 |
Correct |
26 ms |
2432 KB |
Output is correct |
31 |
Correct |
61 ms |
2432 KB |
Output is correct |
32 |
Correct |
21 ms |
2432 KB |
Output is correct |
33 |
Correct |
59 ms |
2432 KB |
Output is correct |
34 |
Correct |
26 ms |
2544 KB |
Output is correct |
35 |
Execution timed out |
2587 ms |
2688 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |