Submission #668759

# Submission time Handle Problem Language Result Execution time Memory
668759 2022-12-04T22:01:39 Z Kahou File Paths (BOI15_fil) C++14
100 / 100
248 ms 71064 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int N = 6050, M = 1e6 + 50;
int n, m, h[N], k, s, p[N];

bool out[N];
int cnt[M];

vector<int> vc[N];
vector<int> vt[N];
vector<int> adj[N];
 
void dfs(int u) {
        for (int x:vt[u]) {
                if (x >= M) continue;
                cnt[x]++;
        }
        if (u > n) {
                int T = k-h[u];
                for (int d = 1; d*d <= T; d++) {
                        if (T%d == 0) {
                                out[u] = out[u] || (cnt[d] > 0);
                                out[u] = out[u] || (cnt[T/d] > 0);
                        }
                }
        }
        for (int v:adj[u]) {
                dfs(v);
        }
        for (int x:vt[u]) {
                if (x >= M) continue;
                cnt[x]--;
        }
}

void solve() {
        cin >> n >> m >> k;
        cin >> s;

        s++;
        vc[0].push_back(0);
        p[0] = -1;
 
        for (int u = 1; u <= n+m; u++) {
                int l;
                cin >> p[u] >> l;
                adj[p[u]].push_back(u);

                l++;
                h[u] = h[p[u]]+l;
                vc[u] = vc[p[u]];
                if (u <= n) vc[u].push_back(h[u]);
        }
 
        for (int u = 0; u <= n; u++) {
                int v = u;
                while (v >= 0) {
                        vt[v].push_back(h[u]-h[v]+s);
                        v = p[v];
                }
        }
 
        dfs(0);
        sort(h, h+n+1);
        for (int u = n+1; u <= n+m; u++) {
                out[u] = out[u] || (h[u] == k);
                for (int x:vc[u]) {
                        int v = lower_bound(h, h+n+1, k-s-(h[u]-x))-h;
                        out[u] = out[u] || (h[v] + s + h[u]-x == k);
                }
                cout << (out[u]?"YES":"NO") << endl;
        }
}
int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        solve();
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 5 ms 2388 KB Output is correct
5 Correct 5 ms 4820 KB Output is correct
6 Correct 5 ms 3324 KB Output is correct
7 Correct 9 ms 5972 KB Output is correct
8 Correct 3 ms 3924 KB Output is correct
9 Correct 3 ms 4052 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 4 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4820 KB Output is correct
2 Correct 11 ms 4872 KB Output is correct
3 Correct 10 ms 5060 KB Output is correct
4 Correct 11 ms 4964 KB Output is correct
5 Correct 198 ms 59744 KB Output is correct
6 Correct 206 ms 60100 KB Output is correct
7 Correct 105 ms 36840 KB Output is correct
8 Correct 113 ms 37344 KB Output is correct
9 Correct 12 ms 4692 KB Output is correct
10 Correct 10 ms 4092 KB Output is correct
11 Correct 11 ms 2764 KB Output is correct
12 Correct 207 ms 58228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 5 ms 2388 KB Output is correct
5 Correct 5 ms 4820 KB Output is correct
6 Correct 5 ms 3324 KB Output is correct
7 Correct 9 ms 5972 KB Output is correct
8 Correct 3 ms 3924 KB Output is correct
9 Correct 3 ms 4052 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 4 ms 2388 KB Output is correct
13 Correct 10 ms 4820 KB Output is correct
14 Correct 11 ms 4872 KB Output is correct
15 Correct 10 ms 5060 KB Output is correct
16 Correct 11 ms 4964 KB Output is correct
17 Correct 198 ms 59744 KB Output is correct
18 Correct 206 ms 60100 KB Output is correct
19 Correct 105 ms 36840 KB Output is correct
20 Correct 113 ms 37344 KB Output is correct
21 Correct 12 ms 4692 KB Output is correct
22 Correct 10 ms 4092 KB Output is correct
23 Correct 11 ms 2764 KB Output is correct
24 Correct 207 ms 58228 KB Output is correct
25 Correct 9 ms 4692 KB Output is correct
26 Correct 10 ms 4924 KB Output is correct
27 Correct 10 ms 4844 KB Output is correct
28 Correct 10 ms 5060 KB Output is correct
29 Correct 200 ms 60456 KB Output is correct
30 Correct 204 ms 60844 KB Output is correct
31 Correct 100 ms 36940 KB Output is correct
32 Correct 100 ms 36624 KB Output is correct
33 Correct 9 ms 4096 KB Output is correct
34 Correct 8 ms 4096 KB Output is correct
35 Correct 11 ms 2692 KB Output is correct
36 Correct 248 ms 71064 KB Output is correct