Submission #146112

# Submission time Handle Problem Language Result Execution time Memory
146112 2019-08-22T08:46:58 Z evpipis File Paths (BOI15_fil) C++14
0 / 100
36 ms 31096 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
const int len = 1e6+5;
int n, m, k, s;
int cnt[len], sz[len], out[len], pre[len];
vector<int> adj[len], vec;

void add(int val){
    if (!vec.empty())
        val += vec.back();
    vec.pb(val);

    for (int i = 0; i < vec.size(); i++)
        cnt[val-vec[i]]++;
}

void del(){
    int val = vec.back();
    for (int i = 0; i < vec.size(); i++)
        cnt[val-vec[i]]--;

    vec.pop_back();
}

void fix(int u, int d){
    d += sz[u];
    pre[d]++;
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (v <= n)
            fix(v, d);
    }
}

void dfs(int u){
    if (u > n){
        int rem = k-(vec.back()+sz[u]);
        //printf("file: u = %d, rem = %d\n", u-n, rem);
        if (rem == 0)
            out[u-n] = 1;
        for (int i = 1; i*i <= rem; i++)
            if (rem%i == 0 && ((i-s >= 0 && cnt[i-s]) || (rem/i-s >= 0 && cnt[rem/i-s])))
                out[u-n] = 1;

        int sum = sz[u]+s;
        for (int i = (int)vec.size()-1; i >= 0; i--){
            if (i > 0)
                sum += vec[i]-vec[i-1];

            if (k-sum >= 0 && pre[k-sum])
                out[u-n] = 1;
        }

        return;
    }

    add(sz[u]);

    //printf("directory: u = %d, vec =", u);
    //for (int i = 0; i < vec.size(); i++)
      //  printf(" %d", vec[i]);
    //printf("\n");

    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        dfs(v);
    }
    del();
}

int main(){
    scanf("%d %d %d %d", &n, &m, &k, &s);
    s++;

    for (int i = 1; i <= n; i++){
        int p;
        scanf("%d %d", &p, &sz[i]);
        sz[i]++;
        adj[p].pb(i);
    }

    for (int i = n+1; i <= n+m; i++){
        int p;
        scanf("%d %d", &p, &sz[i]);
        sz[i]++;
        adj[p].pb(i);
    }

    fix(0, 0);
    dfs(0);

    for (int i = 1; i <= m; i++){
        if (out[i])
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

/*
3 1 10 2
0 1
1 1
2 1
0 2
*/

Compilation message

fil.cpp: In function 'void add(int)':
fil.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++)
                     ~~^~~~~~~~~~~~
fil.cpp: In function 'void del()':
fil.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++)
                     ~~^~~~~~~~~~~~
fil.cpp: In function 'void fix(int, int)':
fil.cpp:30:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[u].size(); j++){
                     ~~^~~~~~~~~~~~~~~
fil.cpp: In function 'void dfs(int)':
fil.cpp:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[u].size(); j++){
                     ~~^~~~~~~~~~~~~~~
fil.cpp: In function 'int main()':
fil.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &n, &m, &k, &s);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fil.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &p, &sz[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
fil.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &p, &sz[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 31096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -