Submission #1020363

# Submission time Handle Problem Language Result Execution time Memory
1020363 2024-07-12T02:12:06 Z adaawf Tree Rotations (POI11_rot) C++17
45 / 100
87 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[500005];
vector<int> g[500005];
ordered_set s[500005];
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

rot.cpp: In function 'long long int dfs(int)':
rot.cpp:33:42: warning: unused variable 'z' [-Wunused-variable]
   33 |     long long int res = 0, c = 0, h = 1, z = g[x][0], t = g[x][1];
      |                                          ^
rot.cpp:33:55: warning: unused variable 't' [-Wunused-variable]
   33 |     long long int res = 0, c = 0, h = 1, z = g[x][0], t = g[x][1];
      |                                                       ^
# Verdict Execution time Memory Grader output
1 Correct 37 ms 51284 KB Output is correct
2 Correct 33 ms 51288 KB Output is correct
3 Correct 33 ms 51284 KB Output is correct
4 Correct 33 ms 51280 KB Output is correct
5 Correct 34 ms 51292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 51288 KB Output is correct
2 Correct 32 ms 51292 KB Output is correct
3 Correct 36 ms 51280 KB Output is correct
4 Correct 34 ms 51288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 51288 KB Output is correct
2 Correct 32 ms 51284 KB Output is correct
3 Correct 34 ms 51548 KB Output is correct
4 Correct 34 ms 51548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 52304 KB Output is correct
2 Correct 43 ms 52420 KB Output is correct
3 Correct 35 ms 52364 KB Output is correct
4 Correct 34 ms 52320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 54352 KB Output is correct
2 Correct 47 ms 54868 KB Output is correct
3 Correct 85 ms 63756 KB Output is correct
4 Correct 45 ms 55132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 87 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 82 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 84 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 80 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -