답안 #146113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146113 2019-08-22T08:49:37 Z evpipis File Paths (BOI15_fil) C++14
33 / 100
95 ms 31496 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 (k-sum >= 0 && pre[k-sum])
                out[u-n] = 1;

            if (i > 0)
                sum += vec[i]-vec[i-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:67: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:75: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:80: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:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &p, &sz[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 30844 KB Output is correct
2 Correct 36 ms 30968 KB Output is correct
3 Correct 36 ms 30968 KB Output is correct
4 Correct 41 ms 30988 KB Output is correct
5 Correct 86 ms 31496 KB Output is correct
6 Correct 95 ms 31352 KB Output is correct
7 Correct 63 ms 30456 KB Output is correct
8 Correct 66 ms 30712 KB Output is correct
9 Correct 36 ms 30584 KB Output is correct
10 Correct 35 ms 30328 KB Output is correct
11 Correct 31 ms 24184 KB Output is correct
12 Correct 65 ms 26744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -