답안 #251832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251832 2020-07-22T10:52:32 Z VEGAnn Uzastopni (COCI15_uzastopni) C++14
80 / 160
345 ms 19064 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 = 10100;
const int V = 110;
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]) {
            if ((l == r && l == a[v])||
                (l > a[v] || r < a[v]))
                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;
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Incorrect 3 ms 768 KB Output isn't correct
4 Incorrect 3 ms 768 KB Output isn't correct
5 Incorrect 4 ms 768 KB Output isn't correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 4 ms 768 KB Output is correct
11 Incorrect 315 ms 18172 KB Output isn't correct
12 Incorrect 300 ms 18168 KB Output isn't correct
13 Correct 286 ms 18296 KB Output is correct
14 Incorrect 341 ms 18980 KB Output isn't correct
15 Incorrect 339 ms 19064 KB Output isn't correct
16 Incorrect 338 ms 19064 KB Output isn't correct
17 Correct 286 ms 18168 KB Output is correct
18 Correct 289 ms 18168 KB Output is correct
19 Incorrect 339 ms 18168 KB Output isn't correct
20 Incorrect 345 ms 18296 KB Output isn't correct