답안 #668664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668664 2022-12-04T11:15:38 Z ParsaS File Paths (BOI15_fil) C++17
100 / 100
229 ms 30404 KB
// In the name of God
#pragma GCC optimize("O2", "unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int N = 6000 + 5, M = 1e6 + 10;
int n, m, k, s;
int par[N], l[N], h[N];
vector<int> adj[N], vec, _div[M], V[N];
bool check[M], ans[N], mark[M];
int vis[M];

void dfs(int v) {
    for (auto u : adj[v]) {
        h[u] = h[v] + l[u];
        dfs(u);
    }
    if (v <= n)
        check[h[v]] = true;
    else
        mark[k - h[v]] = true;
}
void dfs3(int v, int p, int t) {
    if (v <= n)
        vis[h[v] - h[p]] += t;
    for (auto u : adj[v])
        dfs3(u, p, t);
}
inline void upd(int v, int t) {
    dfs3(v, v, t);
}
void dfs2(int v) {
    vec.pb(v);
    if (v <= n) {
        upd(v, 1);
        for (auto u : adj[v]) {
            dfs2(u);
        }
        upd(v, -1);
        vec.pop_back();
        return;
    }
    ans[v] |= h[v] == k;
    for (int i = 0; !ans[v] && i < vec.size() - 1; i++) {
        ans[v] |= k >= h[v] - h[vec[i]] + s && check[k - h[v] + h[vec[i]] - s];
        ans[v] |= k >= h[v] + s && check[k - h[v] - s];
    }
    int L = k - h[v];
    ans[v] |= L >= s && vis[L - s];
    for (auto d : _div[L]) {
        ans[v] |= vis[d - s];
        if (ans[v])
            break;
    }
    vec.pop_back();
}

void solve() {
    cin >> n >> m >> k >> s;
    s++;
    for (int i = 1; i <= n; i++) {
        cin >> par[i] >> l[i];
        l[i]++;
        adj[par[i]].pb(i);
    }
    for (int i = 1; i <= m; i++) {
        cin >> par[i + n] >> l[i + n];
        l[i + n]++;
        adj[par[i + n]].pb(i + n);
    }
    dfs(0);
    for (int i = s; i <= k; i++) {
        for (int j = i; j <= k; j += i) {
            if (mark[j])
                _div[j].pb(i);
        }
    }
    dfs2(0);
    for (int i = n + 1; i <= n + m; i++)
        cout << (ans[i] ? "YES" : "NO") << '\n';
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();

    return 0;
}

Compilation message

fil.cpp: In function 'void dfs2(int)':
fil.cpp:48:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; !ans[v] && i < vec.size() - 1; i++) {
      |                                ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24020 KB Output is correct
2 Correct 14 ms 24088 KB Output is correct
3 Correct 20 ms 24664 KB Output is correct
4 Correct 18 ms 24740 KB Output is correct
5 Correct 21 ms 29232 KB Output is correct
6 Correct 20 ms 28092 KB Output is correct
7 Correct 23 ms 29604 KB Output is correct
8 Correct 19 ms 28500 KB Output is correct
9 Correct 22 ms 28452 KB Output is correct
10 Correct 18 ms 24020 KB Output is correct
11 Correct 24 ms 24148 KB Output is correct
12 Correct 25 ms 24492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 29652 KB Output is correct
2 Correct 26 ms 29740 KB Output is correct
3 Correct 24 ms 29760 KB Output is correct
4 Correct 22 ms 29764 KB Output is correct
5 Correct 188 ms 30284 KB Output is correct
6 Correct 178 ms 30388 KB Output is correct
7 Correct 101 ms 30204 KB Output is correct
8 Correct 107 ms 30212 KB Output is correct
9 Correct 21 ms 29632 KB Output is correct
10 Correct 20 ms 29532 KB Output is correct
11 Correct 27 ms 24252 KB Output is correct
12 Correct 192 ms 26224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24020 KB Output is correct
2 Correct 14 ms 24088 KB Output is correct
3 Correct 20 ms 24664 KB Output is correct
4 Correct 18 ms 24740 KB Output is correct
5 Correct 21 ms 29232 KB Output is correct
6 Correct 20 ms 28092 KB Output is correct
7 Correct 23 ms 29604 KB Output is correct
8 Correct 19 ms 28500 KB Output is correct
9 Correct 22 ms 28452 KB Output is correct
10 Correct 18 ms 24020 KB Output is correct
11 Correct 24 ms 24148 KB Output is correct
12 Correct 25 ms 24492 KB Output is correct
13 Correct 22 ms 29652 KB Output is correct
14 Correct 26 ms 29740 KB Output is correct
15 Correct 24 ms 29760 KB Output is correct
16 Correct 22 ms 29764 KB Output is correct
17 Correct 188 ms 30284 KB Output is correct
18 Correct 178 ms 30388 KB Output is correct
19 Correct 101 ms 30204 KB Output is correct
20 Correct 107 ms 30212 KB Output is correct
21 Correct 21 ms 29632 KB Output is correct
22 Correct 20 ms 29532 KB Output is correct
23 Correct 27 ms 24252 KB Output is correct
24 Correct 192 ms 26224 KB Output is correct
25 Correct 21 ms 29736 KB Output is correct
26 Correct 22 ms 29772 KB Output is correct
27 Correct 22 ms 29824 KB Output is correct
28 Correct 24 ms 29820 KB Output is correct
29 Correct 174 ms 30404 KB Output is correct
30 Correct 178 ms 30400 KB Output is correct
31 Correct 104 ms 30276 KB Output is correct
32 Correct 107 ms 30284 KB Output is correct
33 Correct 21 ms 29604 KB Output is correct
34 Correct 21 ms 29524 KB Output is correct
35 Correct 29 ms 24368 KB Output is correct
36 Correct 229 ms 25384 KB Output is correct