Submission #146109

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

#define pb push_back
const int len = 2e6+5;
int n, m, k, s;
int cnt[len], sz[len], out[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 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;
        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);
    }

    dfs(0);

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

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 dfs(int)':
fil.cpp:46: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:54: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:58: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:65: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 44 ms 47480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 51448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 47480 KB Output isn't correct
2 Halted 0 ms 0 KB -