Submission #30575

# Submission time Handle Problem Language Result Execution time Memory
30575 2017-07-25T03:03:18 Z sampriti File Paths (BOI15_fil) C++14
33 / 100
1000 ms 6556 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int K, S;
vector<int> T[3001];
int dir_par[3001], dir_len[3001];
int sieve[1000001];
int D[3001];
set<int> D_set;
int file_par[3001], file_len[3001];
bool ans[3001];
vector<int> files_by_dir[3001];

void dfs_dist(int i, int d) {
  d += dir_len[i];
  D[i] = d;

  for(int u: T[i]) {
    dfs_dist(u, d);
  }
}

void update(int i, int d, int v) {
  int len = d + S;
  for(int j = len; j <= 1000000; j += len) {
    sieve[j] += v;
  }
  for(int u: T[i]) {
    update(u, d + dir_len[u], v);
  }
}

void dfs_solve_loop(int i) {
  update(i, 0, 1);

  for(int q: files_by_dir[i]) {
    int req = K - file_len[q] - D[file_par[q]];
    if(req > 0 && sieve[req]) {
      ans[q] = true;
    }
  }

  for(int u: T[i]) {
    dfs_solve_loop(u);
  }

  update(i, 0, -1);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0);

  int N, M; cin >> N >> M >> K;
  cin >> S; S++;

  dir_par[0] = -1; dir_len[0] = 1;
  for(int i = 1; i <= N; i++) {
    cin >> dir_par[i] >> dir_len[i];
    dir_len[i]++;
    T[dir_par[i]].push_back(i);
  }

  for(int i = 1; i <= M; i++) {
    cin >> file_par[i] >> file_len[i];
  }

  dfs_dist(0, 0);
  for(int i = 0; i <= N; i++) D_set.insert(D[i]);

  for(int i = 1; i <= M; i++) {
    int req = K - file_len[i];

    if(D[file_par[i]] == req) {
      ans[i] = true;
      continue;
    }

    int j = file_par[i], len = 0;
    while(j != -1) {
      if(D_set.count(req - len - S)) {
        ans[i] = true;
        break;
      }
      len += dir_len[j];
      j = dir_par[j];
    }
  }

  for(int i = 1; i <= M; i++) {
    files_by_dir[file_par[i]].push_back(i);
  }

  dfs_solve_loop(0);

  for(int i = 1; i <= M; i++) {
    if(ans[i]) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 6292 KB Output is correct
2 Correct 39 ms 6292 KB Output is correct
3 Correct 23 ms 6292 KB Output is correct
4 Correct 23 ms 6292 KB Output is correct
5 Correct 3 ms 6292 KB Output is correct
6 Correct 0 ms 6292 KB Output is correct
7 Correct 9 ms 6292 KB Output is correct
8 Correct 6 ms 6292 KB Output is correct
9 Correct 0 ms 6292 KB Output is correct
10 Correct 0 ms 6292 KB Output is correct
11 Correct 263 ms 6292 KB Output is correct
12 Correct 283 ms 6292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6424 KB Output is correct
2 Correct 9 ms 6424 KB Output is correct
3 Correct 6 ms 6424 KB Output is correct
4 Correct 6 ms 6424 KB Output is correct
5 Correct 263 ms 6556 KB Output is correct
6 Correct 453 ms 6556 KB Output is correct
7 Correct 193 ms 6556 KB Output is correct
8 Correct 296 ms 6556 KB Output is correct
9 Correct 9 ms 6424 KB Output is correct
10 Correct 13 ms 6424 KB Output is correct
11 Execution timed out 1000 ms 6424 KB Execution timed out
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 6292 KB Output is correct
2 Correct 39 ms 6292 KB Output is correct
3 Correct 23 ms 6292 KB Output is correct
4 Correct 23 ms 6292 KB Output is correct
5 Correct 3 ms 6292 KB Output is correct
6 Correct 0 ms 6292 KB Output is correct
7 Correct 9 ms 6292 KB Output is correct
8 Correct 6 ms 6292 KB Output is correct
9 Correct 0 ms 6292 KB Output is correct
10 Correct 0 ms 6292 KB Output is correct
11 Correct 263 ms 6292 KB Output is correct
12 Correct 283 ms 6292 KB Output is correct
13 Correct 9 ms 6424 KB Output is correct
14 Correct 9 ms 6424 KB Output is correct
15 Correct 6 ms 6424 KB Output is correct
16 Correct 6 ms 6424 KB Output is correct
17 Correct 263 ms 6556 KB Output is correct
18 Correct 453 ms 6556 KB Output is correct
19 Correct 193 ms 6556 KB Output is correct
20 Correct 296 ms 6556 KB Output is correct
21 Correct 9 ms 6424 KB Output is correct
22 Correct 13 ms 6424 KB Output is correct
23 Execution timed out 1000 ms 6424 KB Execution timed out
24 Halted 0 ms 0 KB -