Submission #668757

# Submission time Handle Problem Language Result Execution time Memory
668757 2022-12-04T21:42:35 Z Kahou File Paths (BOI15_fil) C++14
0 / 100
8 ms 8208 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];
vector<int> adj[N];
bool out[N];
int cnt[M];
vector<int> vc[N];
vector<int> vt[N];
 
void dfs(int u) {
        for (int x:vt[u]) {
                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]) {
                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 764 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 5 ms 2388 KB Output is correct
5 Runtime error 7 ms 7636 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 8208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 764 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 5 ms 2388 KB Output is correct
5 Runtime error 7 ms 7636 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -