# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20928 |
2017-03-21T17:44:33 Z |
gs14004 |
Rope (JOI17_rope) |
C++11 |
|
503 ms |
103796 KB |
#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<int, int> pi;
int n, m, a[1000005];
int ans[5005];
int tab[5005][5005];
void update(int sx, int ex, int sy, int ey, int v){
tab[sx][sy] += v;
tab[ex+1][sy] -= v;
tab[sx][ey+1] -= v;
tab[ex+1][ey+1] += v;
}
void get_table(int s, int e){
memset(tab, 0, sizeof(tab));
for(int i=s+1; i<=e; i+=2){
if(a[i-1] == a[i]){
update(1, a[i-1] - 1, 1, a[i-1] - 1, 2);
update(a[i-1] + 1, m, 1, a[i-1] - 1, 2);
update(1, a[i-1] - 1, a[i-1] + 1, m, 2);
update(a[i-1] + 1, m, a[i-1] + 1, m, 2);
}
else{
int x = min(a[i-1], a[i]);
int y = max(a[i-1], a[i]);
update(1, m, 1, m, 1);
update(1, x-1, 1, x-1, 1);
update(x+1, y-1, 1, x-1, 1);
update(y+1, m, 1, x-1, 1);
update(1, x-1, x+1, y-1, 1);
update(x+1, y-1, x+1, y-1, 1);
update(y+1, m, x+1, y-1, 1);
update(1, x-1, y+1, m, 1);
update(x+1, y-1, y+1, m, 1);
update(y+1, m, y+1, m, 1);
}
}
}
void apply(){
for(int i=1; i<=m; i++){
for(int j=1; j<=m; j++){
tab[i][j] += tab[i-1][j] + tab[i][j-1] - tab[i-1][j-1];
}
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
}
if(m > 5000) return 0;
memset(ans, 0x3f, sizeof(ans));
if(n % 2 == 0){
get_table(1, n);
apply();
for(int i=1; i<=m; i++){
for(int j=1; j<=i; j++){
ans[i] = min(ans[i], tab[i][j]);
ans[j] = min(ans[j], tab[i][j]);
}
}
get_table(2, n-1);
for(int i=1; i<=n; i+=n-1){
update(1, a[i] - 1, 1, a[i] - 1, 1);
update(a[i] + 1, m, 1, a[i] - 1, 1);
update(1, a[i] - 1, a[i] + 1, m, 1);
update(a[i] + 1, m, a[i] + 1, m, 1);
}
apply();
for(int i=1; i<=m; i++){
for(int j=1; j<=i; j++){
ans[i] = min(ans[i], tab[i][j]);
ans[j] = min(ans[j], tab[i][j]);
}
}
}
else{
get_table(1, n-1);
update(1, a[n] - 1, 1, a[n] - 1, 1);
update(a[n] + 1, m, 1, a[n] - 1, 1);
update(1, a[n] - 1, a[n] + 1, m, 1);
update(a[n] + 1, m, a[n] + 1, m, 1);
apply();
for(int i=1; i<=m; i++){
for(int j=1; j<=i; j++){
ans[i] = min(ans[i], tab[i][j]);
ans[j] = min(ans[j], tab[i][j]);
}
}
get_table(2, n);
update(1, a[1] - 1, 1, a[1] - 1, 1);
update(a[1] + 1, m, 1, a[1] - 1, 1);
update(1, a[1] - 1, a[1] + 1, m, 1);
update(a[1] + 1, m, a[1] + 1, m, 1);
apply();
for(int i=1; i<=m; i++){
for(int j=1; j<=i; j++){
ans[i] = min(ans[i], tab[i][j]);
ans[j] = min(ans[j], tab[i][j]);
}
}
}
for(int i=1; i<=m; i++) printf("%d\n", ans[i]);
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:53:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&m);
^
rope.cpp:55:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
103796 KB |
Output is correct |
2 |
Correct |
26 ms |
103796 KB |
Output is correct |
3 |
Correct |
29 ms |
103796 KB |
Output is correct |
4 |
Correct |
33 ms |
103796 KB |
Output is correct |
5 |
Correct |
29 ms |
103796 KB |
Output is correct |
6 |
Correct |
23 ms |
103796 KB |
Output is correct |
7 |
Correct |
26 ms |
103796 KB |
Output is correct |
8 |
Correct |
26 ms |
103796 KB |
Output is correct |
9 |
Correct |
26 ms |
103796 KB |
Output is correct |
10 |
Correct |
26 ms |
103796 KB |
Output is correct |
11 |
Correct |
33 ms |
103796 KB |
Output is correct |
12 |
Correct |
33 ms |
103796 KB |
Output is correct |
13 |
Correct |
23 ms |
103796 KB |
Output is correct |
14 |
Correct |
33 ms |
103796 KB |
Output is correct |
15 |
Correct |
26 ms |
103796 KB |
Output is correct |
16 |
Correct |
33 ms |
103796 KB |
Output is correct |
17 |
Correct |
33 ms |
103796 KB |
Output is correct |
18 |
Correct |
29 ms |
103796 KB |
Output is correct |
19 |
Correct |
29 ms |
103796 KB |
Output is correct |
20 |
Correct |
23 ms |
103796 KB |
Output is correct |
21 |
Correct |
26 ms |
103796 KB |
Output is correct |
22 |
Correct |
39 ms |
103796 KB |
Output is correct |
23 |
Correct |
26 ms |
103796 KB |
Output is correct |
24 |
Correct |
29 ms |
103796 KB |
Output is correct |
25 |
Correct |
29 ms |
103796 KB |
Output is correct |
26 |
Correct |
23 ms |
103796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
103796 KB |
Output is correct |
2 |
Correct |
26 ms |
103796 KB |
Output is correct |
3 |
Correct |
29 ms |
103796 KB |
Output is correct |
4 |
Correct |
33 ms |
103796 KB |
Output is correct |
5 |
Correct |
29 ms |
103796 KB |
Output is correct |
6 |
Correct |
23 ms |
103796 KB |
Output is correct |
7 |
Correct |
26 ms |
103796 KB |
Output is correct |
8 |
Correct |
26 ms |
103796 KB |
Output is correct |
9 |
Correct |
26 ms |
103796 KB |
Output is correct |
10 |
Correct |
26 ms |
103796 KB |
Output is correct |
11 |
Correct |
33 ms |
103796 KB |
Output is correct |
12 |
Correct |
33 ms |
103796 KB |
Output is correct |
13 |
Correct |
23 ms |
103796 KB |
Output is correct |
14 |
Correct |
33 ms |
103796 KB |
Output is correct |
15 |
Correct |
26 ms |
103796 KB |
Output is correct |
16 |
Correct |
33 ms |
103796 KB |
Output is correct |
17 |
Correct |
33 ms |
103796 KB |
Output is correct |
18 |
Correct |
29 ms |
103796 KB |
Output is correct |
19 |
Correct |
29 ms |
103796 KB |
Output is correct |
20 |
Correct |
23 ms |
103796 KB |
Output is correct |
21 |
Correct |
26 ms |
103796 KB |
Output is correct |
22 |
Correct |
39 ms |
103796 KB |
Output is correct |
23 |
Correct |
26 ms |
103796 KB |
Output is correct |
24 |
Correct |
29 ms |
103796 KB |
Output is correct |
25 |
Correct |
29 ms |
103796 KB |
Output is correct |
26 |
Correct |
23 ms |
103796 KB |
Output is correct |
27 |
Correct |
46 ms |
103796 KB |
Output is correct |
28 |
Correct |
39 ms |
103796 KB |
Output is correct |
29 |
Correct |
46 ms |
103796 KB |
Output is correct |
30 |
Correct |
39 ms |
103796 KB |
Output is correct |
31 |
Correct |
46 ms |
103796 KB |
Output is correct |
32 |
Correct |
33 ms |
103796 KB |
Output is correct |
33 |
Correct |
43 ms |
103796 KB |
Output is correct |
34 |
Correct |
49 ms |
103796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
103796 KB |
Output is correct |
2 |
Correct |
26 ms |
103796 KB |
Output is correct |
3 |
Correct |
29 ms |
103796 KB |
Output is correct |
4 |
Correct |
33 ms |
103796 KB |
Output is correct |
5 |
Correct |
29 ms |
103796 KB |
Output is correct |
6 |
Correct |
23 ms |
103796 KB |
Output is correct |
7 |
Correct |
26 ms |
103796 KB |
Output is correct |
8 |
Correct |
26 ms |
103796 KB |
Output is correct |
9 |
Correct |
26 ms |
103796 KB |
Output is correct |
10 |
Correct |
26 ms |
103796 KB |
Output is correct |
11 |
Correct |
33 ms |
103796 KB |
Output is correct |
12 |
Correct |
33 ms |
103796 KB |
Output is correct |
13 |
Correct |
23 ms |
103796 KB |
Output is correct |
14 |
Correct |
33 ms |
103796 KB |
Output is correct |
15 |
Correct |
26 ms |
103796 KB |
Output is correct |
16 |
Correct |
33 ms |
103796 KB |
Output is correct |
17 |
Correct |
33 ms |
103796 KB |
Output is correct |
18 |
Correct |
29 ms |
103796 KB |
Output is correct |
19 |
Correct |
29 ms |
103796 KB |
Output is correct |
20 |
Correct |
23 ms |
103796 KB |
Output is correct |
21 |
Correct |
26 ms |
103796 KB |
Output is correct |
22 |
Correct |
39 ms |
103796 KB |
Output is correct |
23 |
Correct |
26 ms |
103796 KB |
Output is correct |
24 |
Correct |
29 ms |
103796 KB |
Output is correct |
25 |
Correct |
29 ms |
103796 KB |
Output is correct |
26 |
Correct |
23 ms |
103796 KB |
Output is correct |
27 |
Correct |
46 ms |
103796 KB |
Output is correct |
28 |
Correct |
39 ms |
103796 KB |
Output is correct |
29 |
Correct |
46 ms |
103796 KB |
Output is correct |
30 |
Correct |
39 ms |
103796 KB |
Output is correct |
31 |
Correct |
46 ms |
103796 KB |
Output is correct |
32 |
Correct |
33 ms |
103796 KB |
Output is correct |
33 |
Correct |
43 ms |
103796 KB |
Output is correct |
34 |
Correct |
49 ms |
103796 KB |
Output is correct |
35 |
Correct |
56 ms |
103796 KB |
Output is correct |
36 |
Correct |
49 ms |
103796 KB |
Output is correct |
37 |
Correct |
43 ms |
103796 KB |
Output is correct |
38 |
Correct |
53 ms |
103796 KB |
Output is correct |
39 |
Correct |
49 ms |
103796 KB |
Output is correct |
40 |
Correct |
43 ms |
103796 KB |
Output is correct |
41 |
Correct |
56 ms |
103796 KB |
Output is correct |
42 |
Correct |
53 ms |
103796 KB |
Output is correct |
43 |
Correct |
49 ms |
103796 KB |
Output is correct |
44 |
Correct |
46 ms |
103796 KB |
Output is correct |
45 |
Correct |
46 ms |
103796 KB |
Output is correct |
46 |
Correct |
49 ms |
103796 KB |
Output is correct |
47 |
Correct |
59 ms |
103796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
103796 KB |
Output is correct |
2 |
Correct |
26 ms |
103796 KB |
Output is correct |
3 |
Correct |
29 ms |
103796 KB |
Output is correct |
4 |
Correct |
33 ms |
103796 KB |
Output is correct |
5 |
Correct |
29 ms |
103796 KB |
Output is correct |
6 |
Correct |
23 ms |
103796 KB |
Output is correct |
7 |
Correct |
26 ms |
103796 KB |
Output is correct |
8 |
Correct |
26 ms |
103796 KB |
Output is correct |
9 |
Correct |
26 ms |
103796 KB |
Output is correct |
10 |
Correct |
26 ms |
103796 KB |
Output is correct |
11 |
Correct |
33 ms |
103796 KB |
Output is correct |
12 |
Correct |
33 ms |
103796 KB |
Output is correct |
13 |
Correct |
23 ms |
103796 KB |
Output is correct |
14 |
Correct |
33 ms |
103796 KB |
Output is correct |
15 |
Correct |
26 ms |
103796 KB |
Output is correct |
16 |
Correct |
33 ms |
103796 KB |
Output is correct |
17 |
Correct |
33 ms |
103796 KB |
Output is correct |
18 |
Correct |
29 ms |
103796 KB |
Output is correct |
19 |
Correct |
29 ms |
103796 KB |
Output is correct |
20 |
Correct |
23 ms |
103796 KB |
Output is correct |
21 |
Correct |
26 ms |
103796 KB |
Output is correct |
22 |
Correct |
39 ms |
103796 KB |
Output is correct |
23 |
Correct |
26 ms |
103796 KB |
Output is correct |
24 |
Correct |
29 ms |
103796 KB |
Output is correct |
25 |
Correct |
29 ms |
103796 KB |
Output is correct |
26 |
Correct |
23 ms |
103796 KB |
Output is correct |
27 |
Correct |
46 ms |
103796 KB |
Output is correct |
28 |
Correct |
39 ms |
103796 KB |
Output is correct |
29 |
Correct |
46 ms |
103796 KB |
Output is correct |
30 |
Correct |
39 ms |
103796 KB |
Output is correct |
31 |
Correct |
46 ms |
103796 KB |
Output is correct |
32 |
Correct |
33 ms |
103796 KB |
Output is correct |
33 |
Correct |
43 ms |
103796 KB |
Output is correct |
34 |
Correct |
49 ms |
103796 KB |
Output is correct |
35 |
Correct |
56 ms |
103796 KB |
Output is correct |
36 |
Correct |
49 ms |
103796 KB |
Output is correct |
37 |
Correct |
43 ms |
103796 KB |
Output is correct |
38 |
Correct |
53 ms |
103796 KB |
Output is correct |
39 |
Correct |
49 ms |
103796 KB |
Output is correct |
40 |
Correct |
43 ms |
103796 KB |
Output is correct |
41 |
Correct |
56 ms |
103796 KB |
Output is correct |
42 |
Correct |
53 ms |
103796 KB |
Output is correct |
43 |
Correct |
49 ms |
103796 KB |
Output is correct |
44 |
Correct |
46 ms |
103796 KB |
Output is correct |
45 |
Correct |
46 ms |
103796 KB |
Output is correct |
46 |
Correct |
49 ms |
103796 KB |
Output is correct |
47 |
Correct |
59 ms |
103796 KB |
Output is correct |
48 |
Correct |
503 ms |
103796 KB |
Output is correct |
49 |
Correct |
493 ms |
103796 KB |
Output is correct |
50 |
Correct |
469 ms |
103796 KB |
Output is correct |
51 |
Correct |
329 ms |
103796 KB |
Output is correct |
52 |
Correct |
223 ms |
103796 KB |
Output is correct |
53 |
Correct |
386 ms |
103796 KB |
Output is correct |
54 |
Correct |
383 ms |
103796 KB |
Output is correct |
55 |
Correct |
359 ms |
103796 KB |
Output is correct |
56 |
Correct |
359 ms |
103796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
103796 KB |
Output is correct |
2 |
Correct |
26 ms |
103796 KB |
Output is correct |
3 |
Correct |
29 ms |
103796 KB |
Output is correct |
4 |
Correct |
33 ms |
103796 KB |
Output is correct |
5 |
Correct |
29 ms |
103796 KB |
Output is correct |
6 |
Correct |
23 ms |
103796 KB |
Output is correct |
7 |
Correct |
26 ms |
103796 KB |
Output is correct |
8 |
Correct |
26 ms |
103796 KB |
Output is correct |
9 |
Correct |
26 ms |
103796 KB |
Output is correct |
10 |
Correct |
26 ms |
103796 KB |
Output is correct |
11 |
Correct |
33 ms |
103796 KB |
Output is correct |
12 |
Correct |
33 ms |
103796 KB |
Output is correct |
13 |
Correct |
23 ms |
103796 KB |
Output is correct |
14 |
Correct |
33 ms |
103796 KB |
Output is correct |
15 |
Correct |
26 ms |
103796 KB |
Output is correct |
16 |
Correct |
33 ms |
103796 KB |
Output is correct |
17 |
Correct |
33 ms |
103796 KB |
Output is correct |
18 |
Correct |
29 ms |
103796 KB |
Output is correct |
19 |
Correct |
29 ms |
103796 KB |
Output is correct |
20 |
Correct |
23 ms |
103796 KB |
Output is correct |
21 |
Correct |
26 ms |
103796 KB |
Output is correct |
22 |
Correct |
39 ms |
103796 KB |
Output is correct |
23 |
Correct |
26 ms |
103796 KB |
Output is correct |
24 |
Correct |
29 ms |
103796 KB |
Output is correct |
25 |
Correct |
29 ms |
103796 KB |
Output is correct |
26 |
Correct |
23 ms |
103796 KB |
Output is correct |
27 |
Correct |
46 ms |
103796 KB |
Output is correct |
28 |
Correct |
39 ms |
103796 KB |
Output is correct |
29 |
Correct |
46 ms |
103796 KB |
Output is correct |
30 |
Correct |
39 ms |
103796 KB |
Output is correct |
31 |
Correct |
46 ms |
103796 KB |
Output is correct |
32 |
Correct |
33 ms |
103796 KB |
Output is correct |
33 |
Correct |
43 ms |
103796 KB |
Output is correct |
34 |
Correct |
49 ms |
103796 KB |
Output is correct |
35 |
Correct |
56 ms |
103796 KB |
Output is correct |
36 |
Correct |
49 ms |
103796 KB |
Output is correct |
37 |
Correct |
43 ms |
103796 KB |
Output is correct |
38 |
Correct |
53 ms |
103796 KB |
Output is correct |
39 |
Correct |
49 ms |
103796 KB |
Output is correct |
40 |
Correct |
43 ms |
103796 KB |
Output is correct |
41 |
Correct |
56 ms |
103796 KB |
Output is correct |
42 |
Correct |
53 ms |
103796 KB |
Output is correct |
43 |
Correct |
49 ms |
103796 KB |
Output is correct |
44 |
Correct |
46 ms |
103796 KB |
Output is correct |
45 |
Correct |
46 ms |
103796 KB |
Output is correct |
46 |
Correct |
49 ms |
103796 KB |
Output is correct |
47 |
Correct |
59 ms |
103796 KB |
Output is correct |
48 |
Correct |
503 ms |
103796 KB |
Output is correct |
49 |
Correct |
493 ms |
103796 KB |
Output is correct |
50 |
Correct |
469 ms |
103796 KB |
Output is correct |
51 |
Correct |
329 ms |
103796 KB |
Output is correct |
52 |
Correct |
223 ms |
103796 KB |
Output is correct |
53 |
Correct |
386 ms |
103796 KB |
Output is correct |
54 |
Correct |
383 ms |
103796 KB |
Output is correct |
55 |
Correct |
359 ms |
103796 KB |
Output is correct |
56 |
Correct |
359 ms |
103796 KB |
Output is correct |
57 |
Incorrect |
153 ms |
103796 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |