# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105033 | 2019-04-10T08:40:48 Z | bert30702 | Ancient Books (IOI17_books) | C++17 | 36 ms | 31736 KB |
#include <bits/stdc++.h> #include "books.h" #define pii pair<int, int> #define F first #define S second using namespace std; const int MX = 1e6 + 100; int boss[MX]; int Find(int u) { return boss[u] == u ? u : boss[u] = Find(boss[u]); } void merge(int a, int b) { boss[Find(a)] = Find(b); } priority_queue<int> pq[MX]; long long minimum_walk(vector<int> p, int s) { long long sum = 0; for(int i = 0; i < p.size(); i ++) boss[i] = i; for(int i = 0; i < p.size(); i ++) sum += abs(i - p[i]), merge(i, p[i]); for(int i = 0; i < p.size(); i ++) pq[Find(i)].push(i); multiset<pii> ms; for(int i = 0; i < p.size(); i ++) { if(i == Find(i) and p[i] != i) ms.insert({pq[i].top(), i}); } long long ans = 1ll << 60; for(int i = p.size() - 1; i >= s; i --) { int b = (ms.begin()) -> F; ans = min(ans, sum + (i - min(s, b)) * 2); if((--ms.end()) -> F == i) { int ptr = (--ms.end()) -> S; ms.erase(--ms.end()); pq[ptr].pop(); if(pq[ptr].size()) ms.insert({pq[ptr].top(), ptr}); else return ans; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 31616 KB | Output is correct |
2 | Correct | 32 ms | 31736 KB | Output is correct |
3 | Correct | 36 ms | 31616 KB | Output is correct |
4 | Correct | 30 ms | 31616 KB | Output is correct |
5 | Correct | 30 ms | 31608 KB | Output is correct |
6 | Incorrect | 33 ms | 31608 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 31616 KB | Output is correct |
2 | Correct | 32 ms | 31736 KB | Output is correct |
3 | Correct | 36 ms | 31616 KB | Output is correct |
4 | Correct | 30 ms | 31616 KB | Output is correct |
5 | Correct | 30 ms | 31608 KB | Output is correct |
6 | Incorrect | 33 ms | 31608 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 31616 KB | Output is correct |
2 | Correct | 32 ms | 31736 KB | Output is correct |
3 | Correct | 36 ms | 31616 KB | Output is correct |
4 | Correct | 30 ms | 31616 KB | Output is correct |
5 | Correct | 30 ms | 31608 KB | Output is correct |
6 | Incorrect | 33 ms | 31608 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 35 ms | 31724 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4724' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 31616 KB | Output is correct |
2 | Correct | 32 ms | 31736 KB | Output is correct |
3 | Correct | 36 ms | 31616 KB | Output is correct |
4 | Correct | 30 ms | 31616 KB | Output is correct |
5 | Correct | 30 ms | 31608 KB | Output is correct |
6 | Incorrect | 33 ms | 31608 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |