Submission #251772

# Submission time Handle Problem Language Result Execution time Memory
251772 2020-07-22T09:49:47 Z VEGAnn Uzastopni (COCI15_uzastopni) C++14
80 / 160
299 ms 17528 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define sz(x) ((int)x.size())
#define i2 array<int,2>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 10010;
const int V = 101;
const int C = 22;
const int md = 10007;
vector<int> g[N];
bitset<V> f[N][V], lf[V], clr, was[V];
int n, a[N];

void clear(){
    for (int i = 0; i < V; i++)
        lf[i] = clr;
}

void dfs(int v, int p){
    int lst = 0;

    for (int u : g[v]){
        if (u == p) continue;

        dfs(u, v);
    }

    clear();

    for (int i = 0; i < V; i++)
    for (int j = i; j < V; j++)
        was[i][j] = 0;

    was[a[v]][a[v]] = 1;

    lf[a[v]][a[v]] = 1;

    for (int u : g[v]){
        if (u == p) continue;

        for (int l = 1; l < V; l++)
        for (int r = l; r < V; r++)
            if (f[u][l][r]) {
                was[l][r] = 1;
                lf[l][r] = 1;
            }
    }

    for (int l = V - 1; l > 0; l--)
    for (int r = l; r < V; r++)
        if (r + 1 < V && was[l][r])
            lf[l] |= lf[r + 1];

    for (int l = 1; l <= a[v]; l++)
    for (int r = a[v]; r < V; r++)
        f[v][l][r] = lf[l][r];
}

int main() {
#ifdef _LOCAL
    freopen("in.txt","r",stdin); // freopen("output.txt","w",stdout);
#else
//    freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
#endif

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 1; i < n; i++){
        int x, y; cin >> x >> y;
        x--; y--;

        g[x].PB(y);
        g[y].PB(x);
    }

    dfs(0, -1);

    int ans = 0;

    for (int l = 1; l < V; l++)
    for (int r = l; r < V; r++)
        if (f[0][l][r]) {
//            cerr << l << " " << r << '\n';
            ans++;
        }

    cout << ans;

    return 0;
}

Compilation message

uzastopni.cpp: In function 'void dfs(int, int)':
uzastopni.cpp:26:9: warning: unused variable 'lst' [-Wunused-variable]
     int lst = 0;
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Incorrect 4 ms 640 KB Output isn't correct
4 Incorrect 3 ms 640 KB Output isn't correct
5 Incorrect 3 ms 768 KB Output isn't correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Incorrect 261 ms 16788 KB Output isn't correct
12 Incorrect 253 ms 16760 KB Output isn't correct
13 Correct 258 ms 16888 KB Output is correct
14 Incorrect 299 ms 17528 KB Output isn't correct
15 Incorrect 291 ms 17528 KB Output isn't correct
16 Incorrect 293 ms 17512 KB Output isn't correct
17 Correct 255 ms 16792 KB Output is correct
18 Correct 256 ms 16796 KB Output is correct
19 Incorrect 296 ms 16852 KB Output isn't correct
20 Incorrect 285 ms 16760 KB Output isn't correct