답안 #94127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94127 2019-01-16T10:53:20 Z Kastanda File Paths (BOI15_fil) C++11
100 / 100
190 ms 25928 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 3009, MXK = 1000006;
int n, m, k, slen, P[N], L[N], D[N];
int pd[N], ln[N];
bool res[N];
int cnt[MXK];
bitset < MXK > M;
vector < int > divv[N], Q[N], A[N], Adj[N];
void DFS(int v)
{
    for (int &a : A[v])
        cnt[a] ++;

    for (int &u : Adj[v])
        DFS(u);

    for (int &id : Q[v])
    {
        for (int &d : divv[id])
            if (cnt[d])
                res[id] = 1;
    }

    for (int &a : A[v])
        cnt[a] --;
}
int main()
{
    scanf("%d%d%d%d", &n, &m, &k, &slen); slen ++;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d%d", &P[i], &L[i]);
        L[i] ++; Adj[P[i]].push_back(i);
    }
    for (int i = 1; i <= m; i++)
        scanf("%d%d", &pd[i], &ln[i]), ln[i] ++;
    for (int i = 1; i <= n; i++)
        D[i] = D[P[i]] + L[i];

    for (int i = 0; i <= n; i++)
        M[D[i]] = 1;

    for (int i = 1; i <= m; i++)
    {
        // D[?] + slen + D[v] - D[p] + ln[i] == k
        int v = pd[i], p = v;
        while (N)
        {
            int len = slen + D[v] - D[p] + ln[i];
            if (len <= k && M[k - len])
                res[i] = 1;
            if (p == 0)
                break;
            p = P[p];
        }
        if (D[pd[i]] + ln[i] == k)
            res[i] = 1;
    }

    for (int i = 1; i <= m; i++)
    {
        Q[pd[i]].push_back(i);

        int kk = k - D[pd[i]] - ln[i];
        for (int d = 1; d * d <= kk; d ++)
            if (kk % d == 0)
            {
                divv[i].push_back(d);
                divv[i].push_back(kk / d);
            }
    }

    for (int i = 0; i <= n; i++)
    {
        int p = i;
        while (N)
        {
            int len = D[i] - D[p] + slen;
            if (len < MXK)
                A[p].push_back(len);
            if (p == 0)
                break;
            p = P[p];
        }
    }
    DFS(0);

    for (int i = 1; i <= m; i++)
        puts(res[i] ? "YES" : "NO");
    return 0;
}

Compilation message

fil.cpp: In function 'int main()':
fil.cpp:30: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, &slen); slen ++;
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fil.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &P[i], &L[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fil.cpp:37:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &pd[i], &ln[i]), ln[i] ++;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 4 ms 1528 KB Output is correct
5 Correct 7 ms 4728 KB Output is correct
6 Correct 6 ms 3320 KB Output is correct
7 Correct 8 ms 4856 KB Output is correct
8 Correct 5 ms 3960 KB Output is correct
9 Correct 5 ms 4088 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 12 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4984 KB Output is correct
2 Correct 11 ms 4856 KB Output is correct
3 Correct 11 ms 5052 KB Output is correct
4 Correct 11 ms 5112 KB Output is correct
5 Correct 181 ms 24652 KB Output is correct
6 Correct 159 ms 24760 KB Output is correct
7 Correct 98 ms 15932 KB Output is correct
8 Correct 74 ms 16120 KB Output is correct
9 Correct 11 ms 4728 KB Output is correct
10 Correct 10 ms 3960 KB Output is correct
11 Correct 6 ms 1656 KB Output is correct
12 Correct 132 ms 21624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 4 ms 1528 KB Output is correct
5 Correct 7 ms 4728 KB Output is correct
6 Correct 6 ms 3320 KB Output is correct
7 Correct 8 ms 4856 KB Output is correct
8 Correct 5 ms 3960 KB Output is correct
9 Correct 5 ms 4088 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 12 ms 1528 KB Output is correct
13 Correct 11 ms 4984 KB Output is correct
14 Correct 11 ms 4856 KB Output is correct
15 Correct 11 ms 5052 KB Output is correct
16 Correct 11 ms 5112 KB Output is correct
17 Correct 181 ms 24652 KB Output is correct
18 Correct 159 ms 24760 KB Output is correct
19 Correct 98 ms 15932 KB Output is correct
20 Correct 74 ms 16120 KB Output is correct
21 Correct 11 ms 4728 KB Output is correct
22 Correct 10 ms 3960 KB Output is correct
23 Correct 6 ms 1656 KB Output is correct
24 Correct 132 ms 21624 KB Output is correct
25 Correct 10 ms 4728 KB Output is correct
26 Correct 10 ms 4856 KB Output is correct
27 Correct 10 ms 4984 KB Output is correct
28 Correct 10 ms 4984 KB Output is correct
29 Correct 146 ms 24696 KB Output is correct
30 Correct 137 ms 24540 KB Output is correct
31 Correct 86 ms 16052 KB Output is correct
32 Correct 91 ms 15736 KB Output is correct
33 Correct 9 ms 3960 KB Output is correct
34 Correct 9 ms 3960 KB Output is correct
35 Correct 7 ms 1656 KB Output is correct
36 Correct 190 ms 25928 KB Output is correct