# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
51655 |
2018-06-19T17:36:19 Z |
gs13105 |
Rope (JOI17_rope) |
C++17 |
|
2257 ms |
141776 KB |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
using namespace std;
inline int bs_count(vector<int> &v, int x)
{
auto p = equal_range(v.begin(), v.end(), x);
return p.second - p.first;
}
int arr[1000010];
int res[1000010];
int n, m;
void solve(int s)
{
vector<int> cnt(m + 1);
vector<vector<int>> adj(m + 1);
for(int i = s; i <= n; i += 2)
{
int x = arr[i];
int y = arr[i + 1];
cnt[x]++;
cnt[y]++;
if(x && y && x != y)
{
adj[x].push_back(y);
adj[y].push_back(x);
}
}
for(int i = 1; i <= m; i++)
sort(adj[i].begin(), adj[i].end());
vector<pair<int, int>> sor;
for(int i = 1; i <= m; i++)
sor.push_back({ cnt[i], i });
sort(sor.rbegin(), sor.rend());
for(int i = 1; i <= m; i++)
{
priority_queue<int> pq;
pq.push(0);
for(auto &p : sor)
{
int c, y;
tie(c, y) = p;
if(y == i)
continue;
int t = bs_count(adj[i], y);
pq.push(c - t);
if(t == 0)
break;
}
int r = n - cnt[i] - pq.top();
res[i] = min(r, res[i]);
}
}
int main()
{
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%d", &arr[i]);
arr[0] = arr[n + 1] = 0;
for(int i = 1; i <= m; i++)
res[i] = n;
solve(0);
solve(1);
for(int i = 1; i <= m; i++)
printf("%d\n", res[i]);
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
rope.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &arr[i]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
3 ms |
556 KB |
Output is correct |
8 |
Correct |
6 ms |
564 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
3 ms |
776 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
896 KB |
Output is correct |
20 |
Correct |
3 ms |
896 KB |
Output is correct |
21 |
Correct |
2 ms |
896 KB |
Output is correct |
22 |
Correct |
3 ms |
896 KB |
Output is correct |
23 |
Correct |
2 ms |
896 KB |
Output is correct |
24 |
Correct |
2 ms |
896 KB |
Output is correct |
25 |
Correct |
2 ms |
896 KB |
Output is correct |
26 |
Correct |
2 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
3 ms |
556 KB |
Output is correct |
8 |
Correct |
6 ms |
564 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
3 ms |
776 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
896 KB |
Output is correct |
20 |
Correct |
3 ms |
896 KB |
Output is correct |
21 |
Correct |
2 ms |
896 KB |
Output is correct |
22 |
Correct |
3 ms |
896 KB |
Output is correct |
23 |
Correct |
2 ms |
896 KB |
Output is correct |
24 |
Correct |
2 ms |
896 KB |
Output is correct |
25 |
Correct |
2 ms |
896 KB |
Output is correct |
26 |
Correct |
2 ms |
896 KB |
Output is correct |
27 |
Correct |
24 ms |
2012 KB |
Output is correct |
28 |
Correct |
17 ms |
2180 KB |
Output is correct |
29 |
Correct |
28 ms |
2436 KB |
Output is correct |
30 |
Correct |
17 ms |
2436 KB |
Output is correct |
31 |
Correct |
21 ms |
2836 KB |
Output is correct |
32 |
Correct |
16 ms |
2916 KB |
Output is correct |
33 |
Correct |
21 ms |
3240 KB |
Output is correct |
34 |
Correct |
18 ms |
3240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
3 ms |
556 KB |
Output is correct |
8 |
Correct |
6 ms |
564 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
3 ms |
776 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
896 KB |
Output is correct |
20 |
Correct |
3 ms |
896 KB |
Output is correct |
21 |
Correct |
2 ms |
896 KB |
Output is correct |
22 |
Correct |
3 ms |
896 KB |
Output is correct |
23 |
Correct |
2 ms |
896 KB |
Output is correct |
24 |
Correct |
2 ms |
896 KB |
Output is correct |
25 |
Correct |
2 ms |
896 KB |
Output is correct |
26 |
Correct |
2 ms |
896 KB |
Output is correct |
27 |
Correct |
24 ms |
2012 KB |
Output is correct |
28 |
Correct |
17 ms |
2180 KB |
Output is correct |
29 |
Correct |
28 ms |
2436 KB |
Output is correct |
30 |
Correct |
17 ms |
2436 KB |
Output is correct |
31 |
Correct |
21 ms |
2836 KB |
Output is correct |
32 |
Correct |
16 ms |
2916 KB |
Output is correct |
33 |
Correct |
21 ms |
3240 KB |
Output is correct |
34 |
Correct |
18 ms |
3240 KB |
Output is correct |
35 |
Correct |
27 ms |
3760 KB |
Output is correct |
36 |
Correct |
26 ms |
4192 KB |
Output is correct |
37 |
Correct |
26 ms |
4540 KB |
Output is correct |
38 |
Correct |
28 ms |
4888 KB |
Output is correct |
39 |
Correct |
30 ms |
5256 KB |
Output is correct |
40 |
Correct |
31 ms |
5868 KB |
Output is correct |
41 |
Correct |
29 ms |
6104 KB |
Output is correct |
42 |
Correct |
27 ms |
6384 KB |
Output is correct |
43 |
Correct |
25 ms |
6872 KB |
Output is correct |
44 |
Correct |
27 ms |
7228 KB |
Output is correct |
45 |
Correct |
35 ms |
7516 KB |
Output is correct |
46 |
Correct |
37 ms |
7852 KB |
Output is correct |
47 |
Correct |
30 ms |
8332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
3 ms |
556 KB |
Output is correct |
8 |
Correct |
6 ms |
564 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
3 ms |
776 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
896 KB |
Output is correct |
20 |
Correct |
3 ms |
896 KB |
Output is correct |
21 |
Correct |
2 ms |
896 KB |
Output is correct |
22 |
Correct |
3 ms |
896 KB |
Output is correct |
23 |
Correct |
2 ms |
896 KB |
Output is correct |
24 |
Correct |
2 ms |
896 KB |
Output is correct |
25 |
Correct |
2 ms |
896 KB |
Output is correct |
26 |
Correct |
2 ms |
896 KB |
Output is correct |
27 |
Correct |
24 ms |
2012 KB |
Output is correct |
28 |
Correct |
17 ms |
2180 KB |
Output is correct |
29 |
Correct |
28 ms |
2436 KB |
Output is correct |
30 |
Correct |
17 ms |
2436 KB |
Output is correct |
31 |
Correct |
21 ms |
2836 KB |
Output is correct |
32 |
Correct |
16 ms |
2916 KB |
Output is correct |
33 |
Correct |
21 ms |
3240 KB |
Output is correct |
34 |
Correct |
18 ms |
3240 KB |
Output is correct |
35 |
Correct |
27 ms |
3760 KB |
Output is correct |
36 |
Correct |
26 ms |
4192 KB |
Output is correct |
37 |
Correct |
26 ms |
4540 KB |
Output is correct |
38 |
Correct |
28 ms |
4888 KB |
Output is correct |
39 |
Correct |
30 ms |
5256 KB |
Output is correct |
40 |
Correct |
31 ms |
5868 KB |
Output is correct |
41 |
Correct |
29 ms |
6104 KB |
Output is correct |
42 |
Correct |
27 ms |
6384 KB |
Output is correct |
43 |
Correct |
25 ms |
6872 KB |
Output is correct |
44 |
Correct |
27 ms |
7228 KB |
Output is correct |
45 |
Correct |
35 ms |
7516 KB |
Output is correct |
46 |
Correct |
37 ms |
7852 KB |
Output is correct |
47 |
Correct |
30 ms |
8332 KB |
Output is correct |
48 |
Correct |
337 ms |
22408 KB |
Output is correct |
49 |
Correct |
324 ms |
27072 KB |
Output is correct |
50 |
Correct |
285 ms |
31528 KB |
Output is correct |
51 |
Correct |
301 ms |
35612 KB |
Output is correct |
52 |
Correct |
291 ms |
38316 KB |
Output is correct |
53 |
Correct |
283 ms |
43284 KB |
Output is correct |
54 |
Correct |
303 ms |
46916 KB |
Output is correct |
55 |
Correct |
289 ms |
51092 KB |
Output is correct |
56 |
Correct |
333 ms |
55464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
3 ms |
556 KB |
Output is correct |
8 |
Correct |
6 ms |
564 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
3 ms |
776 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
896 KB |
Output is correct |
20 |
Correct |
3 ms |
896 KB |
Output is correct |
21 |
Correct |
2 ms |
896 KB |
Output is correct |
22 |
Correct |
3 ms |
896 KB |
Output is correct |
23 |
Correct |
2 ms |
896 KB |
Output is correct |
24 |
Correct |
2 ms |
896 KB |
Output is correct |
25 |
Correct |
2 ms |
896 KB |
Output is correct |
26 |
Correct |
2 ms |
896 KB |
Output is correct |
27 |
Correct |
24 ms |
2012 KB |
Output is correct |
28 |
Correct |
17 ms |
2180 KB |
Output is correct |
29 |
Correct |
28 ms |
2436 KB |
Output is correct |
30 |
Correct |
17 ms |
2436 KB |
Output is correct |
31 |
Correct |
21 ms |
2836 KB |
Output is correct |
32 |
Correct |
16 ms |
2916 KB |
Output is correct |
33 |
Correct |
21 ms |
3240 KB |
Output is correct |
34 |
Correct |
18 ms |
3240 KB |
Output is correct |
35 |
Correct |
27 ms |
3760 KB |
Output is correct |
36 |
Correct |
26 ms |
4192 KB |
Output is correct |
37 |
Correct |
26 ms |
4540 KB |
Output is correct |
38 |
Correct |
28 ms |
4888 KB |
Output is correct |
39 |
Correct |
30 ms |
5256 KB |
Output is correct |
40 |
Correct |
31 ms |
5868 KB |
Output is correct |
41 |
Correct |
29 ms |
6104 KB |
Output is correct |
42 |
Correct |
27 ms |
6384 KB |
Output is correct |
43 |
Correct |
25 ms |
6872 KB |
Output is correct |
44 |
Correct |
27 ms |
7228 KB |
Output is correct |
45 |
Correct |
35 ms |
7516 KB |
Output is correct |
46 |
Correct |
37 ms |
7852 KB |
Output is correct |
47 |
Correct |
30 ms |
8332 KB |
Output is correct |
48 |
Correct |
337 ms |
22408 KB |
Output is correct |
49 |
Correct |
324 ms |
27072 KB |
Output is correct |
50 |
Correct |
285 ms |
31528 KB |
Output is correct |
51 |
Correct |
301 ms |
35612 KB |
Output is correct |
52 |
Correct |
291 ms |
38316 KB |
Output is correct |
53 |
Correct |
283 ms |
43284 KB |
Output is correct |
54 |
Correct |
303 ms |
46916 KB |
Output is correct |
55 |
Correct |
289 ms |
51092 KB |
Output is correct |
56 |
Correct |
333 ms |
55464 KB |
Output is correct |
57 |
Correct |
2257 ms |
136320 KB |
Output is correct |
58 |
Correct |
1731 ms |
136320 KB |
Output is correct |
59 |
Correct |
1775 ms |
136320 KB |
Output is correct |
60 |
Correct |
2035 ms |
136320 KB |
Output is correct |
61 |
Correct |
1999 ms |
141776 KB |
Output is correct |
62 |
Correct |
796 ms |
141776 KB |
Output is correct |
63 |
Correct |
1109 ms |
141776 KB |
Output is correct |
64 |
Correct |
906 ms |
141776 KB |
Output is correct |
65 |
Correct |
606 ms |
141776 KB |
Output is correct |