# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
599099 |
2022-07-19T10:03:57 Z |
piOOE |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
62932 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000000, M = 10000000;
int a[N], ans[M], cnt[M];
vector<int> g[N];
priority_queue<pair<int, int>> pq;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(ans, 0x3f, sizeof(ans));
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
--a[i];
++cnt[a[i]];
}
for (int i = 0; i < m; ++i) {
pq.push({cnt[i], i});
}
for (int k = 0; k < 2; ++k) {
for (int i = 0; i < m; ++i) {
g[i].clear();
}
for (int i = k; i + 1 < n; i += 2) {
if (a[i] != a[i + 1]) {
g[a[i]].push_back(a[i + 1]);
g[a[i + 1]].push_back(a[i]);
}
}
for (int c = 0; c < m; ++c) {
int now = cnt[c];
auto upd = [](int v, int nw) {
pq.push({cnt[v] = nw, v});
};
upd(c, 0);
for (int to : g[c]) {
upd(to, cnt[to] - 1);
}
while (cnt[pq.top().second] != pq.top().second) {
pq.pop();
}
ans[c] = min(ans[c], n - now - pq.top().second);
upd(c, now);
for (int to : g[c]) {
upd(to, cnt[to] + 1);
}
}
}
for (int i = 0; i < m; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2589 ms |
62932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2589 ms |
62932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2589 ms |
62932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2589 ms |
62932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2589 ms |
62932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |