Submission #32934

# Submission time Handle Problem Language Result Execution time Memory
32934 2017-10-17T14:51:10 Z aome Rope (JOI17_rope) C++14
0 / 100
0 ms 6084 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
const int N = 100005;

int n, m, cnt[N];
int a[N], res[N];
int val[N];
vector<int> p[N];

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i], cnt[a[i]]++, p[a[i]].push_back(i);
	}
	set<ii> s;
	for (int i = 1; i <= m; ++i) s.insert(ii(cnt[i], i));
	for (int i = 1; i <= m; ++i) {
		res[i] = 1e9;
		for (int j = 0; j < 2; ++j) {
			vector<int> go;
			int sum = 0;
			for (int k = 0; k < p[i].size(); ++k) {
				if (p[i][k] % 2 == j) {
					int cur = a[p[i][k] - 1];
					if (p[i][k] > 1 && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
				else {
					int cur = a[p[i][k] + 1];
					if (p[i][k] < n && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
			}
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]], go[k])));
				s.insert(ii(cnt[go[k]] - val[go[k]], go[k]));
			}
			s.erase(s.find(ii(cnt[i], i)));
			res[i] = min(res[i], n - ((*(--s.end())).first + cnt[i]));
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]] - val[go[k]], go[k])));
				s.insert(ii(cnt[go[k]], go[k]));				
			}
			s.insert(ii(cnt[i], i));
			for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
		}
		cout << res[i] << '\n';
	}
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:25:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < p[i].size(); ++k) {
                      ^
rope.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < go.size(); ++k) {
                      ^
rope.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < go.size(); ++k) {
                      ^
rope.cpp:50:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
                      ^
rope.cpp:24:8: warning: unused variable 'sum' [-Wunused-variable]
    int sum = 0;
        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6084 KB Output is correct
2 Correct 0 ms 6084 KB Output is correct
3 Correct 0 ms 6084 KB Output is correct
4 Correct 0 ms 6084 KB Output is correct
5 Correct 0 ms 6084 KB Output is correct
6 Correct 0 ms 6084 KB Output is correct
7 Correct 0 ms 6084 KB Output is correct
8 Correct 0 ms 6084 KB Output is correct
9 Correct 0 ms 6084 KB Output is correct
10 Correct 0 ms 6084 KB Output is correct
11 Correct 0 ms 6084 KB Output is correct
12 Correct 0 ms 6084 KB Output is correct
13 Correct 0 ms 6084 KB Output is correct
14 Correct 0 ms 6084 KB Output is correct
15 Correct 0 ms 6084 KB Output is correct
16 Correct 0 ms 6084 KB Output is correct
17 Correct 0 ms 6084 KB Output is correct
18 Correct 0 ms 6084 KB Output is correct
19 Correct 0 ms 6084 KB Output is correct
20 Correct 0 ms 6084 KB Output is correct
21 Correct 0 ms 6084 KB Output is correct
22 Runtime error 0 ms 6084 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6084 KB Output is correct
2 Correct 0 ms 6084 KB Output is correct
3 Correct 0 ms 6084 KB Output is correct
4 Correct 0 ms 6084 KB Output is correct
5 Correct 0 ms 6084 KB Output is correct
6 Correct 0 ms 6084 KB Output is correct
7 Correct 0 ms 6084 KB Output is correct
8 Correct 0 ms 6084 KB Output is correct
9 Correct 0 ms 6084 KB Output is correct
10 Correct 0 ms 6084 KB Output is correct
11 Correct 0 ms 6084 KB Output is correct
12 Correct 0 ms 6084 KB Output is correct
13 Correct 0 ms 6084 KB Output is correct
14 Correct 0 ms 6084 KB Output is correct
15 Correct 0 ms 6084 KB Output is correct
16 Correct 0 ms 6084 KB Output is correct
17 Correct 0 ms 6084 KB Output is correct
18 Correct 0 ms 6084 KB Output is correct
19 Correct 0 ms 6084 KB Output is correct
20 Correct 0 ms 6084 KB Output is correct
21 Correct 0 ms 6084 KB Output is correct
22 Runtime error 0 ms 6084 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6084 KB Output is correct
2 Correct 0 ms 6084 KB Output is correct
3 Correct 0 ms 6084 KB Output is correct
4 Correct 0 ms 6084 KB Output is correct
5 Correct 0 ms 6084 KB Output is correct
6 Correct 0 ms 6084 KB Output is correct
7 Correct 0 ms 6084 KB Output is correct
8 Correct 0 ms 6084 KB Output is correct
9 Correct 0 ms 6084 KB Output is correct
10 Correct 0 ms 6084 KB Output is correct
11 Correct 0 ms 6084 KB Output is correct
12 Correct 0 ms 6084 KB Output is correct
13 Correct 0 ms 6084 KB Output is correct
14 Correct 0 ms 6084 KB Output is correct
15 Correct 0 ms 6084 KB Output is correct
16 Correct 0 ms 6084 KB Output is correct
17 Correct 0 ms 6084 KB Output is correct
18 Correct 0 ms 6084 KB Output is correct
19 Correct 0 ms 6084 KB Output is correct
20 Correct 0 ms 6084 KB Output is correct
21 Correct 0 ms 6084 KB Output is correct
22 Runtime error 0 ms 6084 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6084 KB Output is correct
2 Correct 0 ms 6084 KB Output is correct
3 Correct 0 ms 6084 KB Output is correct
4 Correct 0 ms 6084 KB Output is correct
5 Correct 0 ms 6084 KB Output is correct
6 Correct 0 ms 6084 KB Output is correct
7 Correct 0 ms 6084 KB Output is correct
8 Correct 0 ms 6084 KB Output is correct
9 Correct 0 ms 6084 KB Output is correct
10 Correct 0 ms 6084 KB Output is correct
11 Correct 0 ms 6084 KB Output is correct
12 Correct 0 ms 6084 KB Output is correct
13 Correct 0 ms 6084 KB Output is correct
14 Correct 0 ms 6084 KB Output is correct
15 Correct 0 ms 6084 KB Output is correct
16 Correct 0 ms 6084 KB Output is correct
17 Correct 0 ms 6084 KB Output is correct
18 Correct 0 ms 6084 KB Output is correct
19 Correct 0 ms 6084 KB Output is correct
20 Correct 0 ms 6084 KB Output is correct
21 Correct 0 ms 6084 KB Output is correct
22 Runtime error 0 ms 6084 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6084 KB Output is correct
2 Correct 0 ms 6084 KB Output is correct
3 Correct 0 ms 6084 KB Output is correct
4 Correct 0 ms 6084 KB Output is correct
5 Correct 0 ms 6084 KB Output is correct
6 Correct 0 ms 6084 KB Output is correct
7 Correct 0 ms 6084 KB Output is correct
8 Correct 0 ms 6084 KB Output is correct
9 Correct 0 ms 6084 KB Output is correct
10 Correct 0 ms 6084 KB Output is correct
11 Correct 0 ms 6084 KB Output is correct
12 Correct 0 ms 6084 KB Output is correct
13 Correct 0 ms 6084 KB Output is correct
14 Correct 0 ms 6084 KB Output is correct
15 Correct 0 ms 6084 KB Output is correct
16 Correct 0 ms 6084 KB Output is correct
17 Correct 0 ms 6084 KB Output is correct
18 Correct 0 ms 6084 KB Output is correct
19 Correct 0 ms 6084 KB Output is correct
20 Correct 0 ms 6084 KB Output is correct
21 Correct 0 ms 6084 KB Output is correct
22 Runtime error 0 ms 6084 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -