Submission #251771

# Submission time Handle Problem Language Result Execution time Memory
251771 2020-07-22T09:48:27 Z VEGAnn Uzastopni (COCI15_uzastopni) C++14
80 / 160
305 ms 17560 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;

//        cerr << lf[lst][1][3] << '\n';

        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 (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 3 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 4 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 4 ms 768 KB Output is correct
11 Incorrect 264 ms 16888 KB Output isn't correct
12 Incorrect 251 ms 16760 KB Output isn't correct
13 Correct 265 ms 16760 KB Output is correct
14 Incorrect 286 ms 17560 KB Output isn't correct
15 Incorrect 305 ms 17528 KB Output isn't correct
16 Incorrect 303 ms 17528 KB Output isn't correct
17 Correct 264 ms 16760 KB Output is correct
18 Correct 261 ms 16760 KB Output is correct
19 Incorrect 297 ms 16876 KB Output isn't correct
20 Incorrect 283 ms 16764 KB Output isn't correct