# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1020364 | 2024-07-12T02:13:39 Z | adaawf | Tree Rotations (POI11_rot) | C++17 | 156 ms | 65536 KB |
#include <iostream> #include <vector> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int c = 1, a[400005]; vector<int> g[400005]; ordered_set s[400005]; void trya() { int h = c, w; cin >> w; if (w == 0) { c++; int k = c, l; trya(); c++; l = c; trya(); g[h].push_back(k); g[h].push_back(l); } else a[h] = w; } long long int dfs(int x) { if (g[x].size() == 0) { s[x].insert(a[x]); return 0; } long long int res = 0, c = 0, h = 1, z = g[x][0], t = g[x][1]; for (int w : g[x]) { c += dfs(w); h *= s[w].size(); int flag = 0; if (s[w].size() > s[x].size()) { s[x].swap(s[w]); flag = 1; } for (int v : s[w]) { if (flag == 1) res += s[x].order_of_key(v); else res += s[x].size() - s[x].order_of_key(v); } for (int v : s[w]) { s[x].insert(v); } } return min(res, h - res) + c; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; trya(); cout << dfs(1); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 41160 KB | Output is correct |
2 | Correct | 26 ms | 41068 KB | Output is correct |
3 | Correct | 35 ms | 41108 KB | Output is correct |
4 | Correct | 26 ms | 41052 KB | Output is correct |
5 | Correct | 26 ms | 41048 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 41192 KB | Output is correct |
2 | Correct | 25 ms | 41048 KB | Output is correct |
3 | Correct | 26 ms | 41048 KB | Output is correct |
4 | Correct | 33 ms | 41012 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 41304 KB | Output is correct |
2 | Correct | 27 ms | 41300 KB | Output is correct |
3 | Correct | 27 ms | 41308 KB | Output is correct |
4 | Correct | 26 ms | 41396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 42020 KB | Output is correct |
2 | Correct | 30 ms | 42140 KB | Output is correct |
3 | Correct | 30 ms | 42220 KB | Output is correct |
4 | Correct | 35 ms | 42328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 44112 KB | Output is correct |
2 | Correct | 42 ms | 44632 KB | Output is correct |
3 | Correct | 79 ms | 53332 KB | Output is correct |
4 | Correct | 39 ms | 44880 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 108 ms | 58624 KB | Output is correct |
2 | Correct | 75 ms | 55380 KB | Output is correct |
3 | Correct | 83 ms | 57924 KB | Output is correct |
4 | Correct | 79 ms | 58184 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 97 ms | 64340 KB | Output is correct |
2 | Correct | 104 ms | 64084 KB | Output is correct |
3 | Correct | 156 ms | 65312 KB | Output is correct |
4 | Correct | 100 ms | 59496 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 141 ms | 63992 KB | Output is correct |
2 | Correct | 144 ms | 65536 KB | Output is correct |
3 | Runtime error | 93 ms | 65536 KB | Execution killed with signal 9 |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 96 ms | 65536 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 117 ms | 65536 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 120 ms | 65536 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |