Submission #141434

# Submission time Handle Problem Language Result Execution time Memory
141434 2019-08-08T05:36:24 Z meatrow Uzastopni (COCI15_uzastopni) C++17
112 / 160
8 ms 1528 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 1e4 + 5;
const int M = 101;

int jojoke[N];
int l[N], r[N];
vector<int> g[N];
int a[M];
pair<int, int> p[N * 2];

void dfs(int v) {
    l[v] = r[v] = jojoke[v];
    for (int u : g[v]) {
        dfs(u);
    }
    fill(a, a + M, 0);
    int sz = 0;
    for (int u : g[v]) {
        if (l[u] <= jojoke[v] && jojoke[v] <= r[u]) {
            if (jojoke[u] < jojoke[v]) {
                p[sz++] = { l[u], 1 };
                p[sz++] = { jojoke[v] + 1, -1 };
            } else {
                p[sz++] = { jojoke[v], 1 };
                p[sz++] = { r[u] + 1, -1 };
            }
        } else {
            p[sz++] = { l[u], 1 };
            p[sz++] = { r[u] + 1, -1 }; 
        }
    }
    sort(p, p + sz);
    int b = 0;
    for (int i = 0; i < sz; i++) {
        b += p[i].second;
        if (b > 0) {
            for (int j = p[i].first; j < p[i + 1].first; j++) {
                a[j] = 1;
            }
        }
    }
    for (int i = jojoke[v] + 1; i < M; i++) {
        if (a[i] == 0) {
            break;
        }
        r[v] = i;
    }
    for (int i = jojoke[v] - 1; i > 0; i--) {
        if (a[i] == 0) {
            break;
        }
        l[v] = i;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> jojoke[i];
    }
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
    }
    dfs(1);
    cout << (jojoke[1] - l[1] + 1) * (r[1] - jojoke[1] + 1) << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 632 KB Output isn't correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Incorrect 2 ms 632 KB Output isn't correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 636 KB Output is correct
11 Incorrect 8 ms 1016 KB Output isn't correct
12 Incorrect 8 ms 1016 KB Output isn't correct
13 Correct 8 ms 1016 KB Output is correct
14 Correct 8 ms 1528 KB Output is correct
15 Correct 8 ms 1528 KB Output is correct
16 Correct 8 ms 1528 KB Output is correct
17 Correct 7 ms 1016 KB Output is correct
18 Correct 8 ms 1020 KB Output is correct
19 Incorrect 7 ms 908 KB Output isn't correct
20 Incorrect 7 ms 892 KB Output isn't correct