Submission #282023

# Submission time Handle Problem Language Result Execution time Memory
282023 2020-08-23T19:39:19 Z thecodingwizard File Paths (BOI15_fil) C++11
33 / 100
284 ms 5112 KB
#include <bits/stdc++.h>

using namespace std;

// Case 1: exact length
// Case 2: some prefix of directories + symlink + some suffix to file
// Case 3: dist to file + constant*(place symlink in a parent directory of file)

int n, m, k, s; 
int dirLen[3001];
vector<int> subdirs[3001];
vector<int> dirfiles[3001];
int fileLen[3001];
bool ans[3001];
set<int> prefixLengths;

void dfsPrefixes(int u, int d) {
    prefixLengths.insert(d);
    for (int dir : subdirs[u]) {
        dfsPrefixes(dir, d + dirLen[dir]);
    }
}

vector<int> prefixLenStack;
int numCaseThreeLengths[1000001];

void dfsCaseThree(int u, int d, int v) {
    if (d + s > 1000000) return;
    numCaseThreeLengths[d+s] += v;

    for (int sub : subdirs[u]) {
        dfsCaseThree(sub, d + dirLen[sub], v);
    }
}

void dfs(int u, int d) {
    prefixLenStack.push_back(d);

    dfsCaseThree(u, 0, 1);

    for (int f : dirfiles[u]) {
        int totLen = fileLen[f] + d;

        // case 1
        if (totLen == k) ans[f] = true;

        // case 2
        for (int pfx : prefixLenStack) {
            int suffix = totLen - pfx + s;
            int want = k - suffix;
            if (prefixLengths.count(want)) ans[f] = true;
        }

        /*
        // case 3
        int want = k - totLen;
        if (want > 0) {
            for (int i = 1; i*i <= want; i++) {
                if (want % i == 0 && numCaseThreeLengths[want/i] > 0) ans[f] = true;
            }
        }
        */
    }

    for (int sub : subdirs[u]) {
        dfs(sub, d + dirLen[sub]);
    }

    dfsCaseThree(u, 0, -1);

    prefixLenStack.pop_back();
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> m >> k >> s; s++;
    for (int i = 1; i <= n; i++) {
        int p, l; cin >> p >> l;
        dirLen[i] = l+1;
        subdirs[p].push_back(i);
    }
    for (int i = 0; i < m; i++) {
        int p, l; cin >> p >> l;
        fileLen[i] = l+1;
        dirfiles[p].push_back(i);
    }

    // generate prefixes
    dfsPrefixes(0, 0);

    dfs(0, 0);

    for (int i = 0; i < m; i++) {
        if (ans[i]) cout << "YES" << "\n";
        else cout << "NO" << "\n";
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4480 KB Output is correct
2 Correct 7 ms 4480 KB Output is correct
3 Correct 7 ms 4608 KB Output is correct
4 Correct 6 ms 4608 KB Output is correct
5 Correct 281 ms 4752 KB Output is correct
6 Correct 284 ms 5112 KB Output is correct
7 Correct 130 ms 4600 KB Output is correct
8 Correct 138 ms 4856 KB Output is correct
9 Correct 8 ms 4096 KB Output is correct
10 Correct 8 ms 3584 KB Output is correct
11 Correct 10 ms 896 KB Output is correct
12 Correct 213 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -