# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961987 | 2024-04-13T01:42:47 Z | Kakarot | Cat Exercise (JOI23_ho_t4) | C++ | 0 ms | 348 KB |
#include <bits/stdc++.h> #define int int64_t using namespace std; void setIO() { cin.tie(0)->sync_with_stdio(0); } void solve() { //cout << "tc/death"; int n, idx; cin >> n; vector<pair<int, int>> tc(n); for(int i = 0; i < n; i++) { cin >> tc[i].first; tc[i].second = i; if(tc[i].first == n) idx = tc[i].second; } // for(auto &x : tc) cout << x.first << ' ' << x.second << '\n'; // cout << idx; vector<vector<int>> adj(n); for(int i = 0; i < n-1; i++) { int u, v; cin >> u >> v; adj[--u].push_back(--v); adj[v].push_back(u); } priority_queue<pair<int, int>> pq; pq.push({n, idx}); int ans = 0; if(idx > n-1-idx) { //cout << "TC"; for(int i = 0; i < idx; i++) { pq.push(tc[i]); } while(!pq.empty()) { auto a = pq.top(); while(!pq.empty() && pq.top().second >= a.second) pq.pop(); //if(pq.empty()) break; ans += abs(a.second-pq.top().second); } } else { //cout << "TC/death"; //cout << idx; for(int i = idx+1; i < n; i++) pq.push(tc[i]); //while(!pq.empty()) { cout << pq.top().first << ' ' << pq.top().second << '\n'; pq.pop(); } while(!pq.empty()) { auto a = pq.top(); while(!pq.empty() && pq.top().second <= a.second) pq.pop(); //if(pq.empty()) break; ans += abs(a.second-pq.top().second); } //cout << ans; } cout << ans; } int32_t main() { setIO(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |