Submission #851744

# Submission time Handle Problem Language Result Execution time Memory
851744 2023-09-20T14:06:01 Z 12345678 Tropical Garden (IOI11_garden) C++17
100 / 100
4499 ms 41464 KB
#include "garden.h"
#include "gardenlib.h"
#include "bits/stdc++.h"

using namespace std;

const int nx=3e5+100;
int ds[nx], dss[nx], c=INT_MAX, cs=INT_MAX, ans, n, p, v[nx], vs[nx];
bool vs1[2*nx], vs2[2*nx];
vector<int> d[2*nx];

void dfs(int u, int s)
{
    if (vs1[u]) return;
    vs1[u]=1; ds[u]=s;
    for (auto v:d[u])
    {
        if (v==p) c=s+1;
        else dfs(v, s+1);
    } 
}

void dfs2(int u, int s)
{
    if (vs2[u]) return;
    vs2[u]=1; dss[u]=s;
    for (auto v:d[u])
    {
        if (v==p+n) cs=s+1;
        else dfs2(v, s+1);
    }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    for (int i=0; i<N; i++) ds[i]=dss[i]=INT_MAX, vs[i]=v[i]=-1;
    n=N; p=P;
    for (int i=0; i<M; i++)
    {
        if (v[R[i][0]]==-1) v[R[i][0]]=R[i][1];
        else if (vs[R[i][0]]==-1) vs[R[i][0]]=R[i][1];
        if (v[R[i][1]]==-1) v[R[i][1]]=R[i][0];
        else if (vs[R[i][1]]==-1) vs[R[i][1]]=R[i][0];
    }
    for (int i=0; i<N; i++) if (vs[i]==-1) vs[i]=v[i];
    for (int i=0; i<N; i++)
    {
        if (v[v[i]]==i) d[v[i]+n].push_back(i);
        else d[v[i]].push_back(i);
        if (v[vs[i]]==i) d[vs[i]+n].push_back(i+n);
        else d[vs[i]].push_back(i+n);
    }
    dfs(p, 0);
    dfs2(p+n, 0);
    for (int i=0; i<Q; i++)
    {
        int cnt(0);
        for (int j=0; j<n; j++)
        {
            if (((G[i]-ds[j])%c==0&&ds[j]<=G[i])||((G[i]-dss[j])%cs==0&&dss[j]<=G[i])) cnt++;
        }
        answer(cnt);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21280 KB Output is correct
3 Correct 4 ms 21080 KB Output is correct
4 Correct 4 ms 21080 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 5 ms 21080 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21280 KB Output is correct
3 Correct 4 ms 21080 KB Output is correct
4 Correct 4 ms 21080 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 5 ms 21080 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
10 Correct 5 ms 21080 KB Output is correct
11 Correct 9 ms 22360 KB Output is correct
12 Correct 18 ms 22364 KB Output is correct
13 Correct 31 ms 34396 KB Output is correct
14 Correct 47 ms 29260 KB Output is correct
15 Correct 54 ms 29520 KB Output is correct
16 Correct 49 ms 28452 KB Output is correct
17 Correct 38 ms 27472 KB Output is correct
18 Correct 16 ms 22872 KB Output is correct
19 Correct 45 ms 29264 KB Output is correct
20 Correct 74 ms 29668 KB Output is correct
21 Correct 46 ms 27984 KB Output is correct
22 Correct 39 ms 27476 KB Output is correct
23 Correct 46 ms 30204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21280 KB Output is correct
3 Correct 4 ms 21080 KB Output is correct
4 Correct 4 ms 21080 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 5 ms 21080 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
10 Correct 5 ms 21080 KB Output is correct
11 Correct 9 ms 22360 KB Output is correct
12 Correct 18 ms 22364 KB Output is correct
13 Correct 31 ms 34396 KB Output is correct
14 Correct 47 ms 29260 KB Output is correct
15 Correct 54 ms 29520 KB Output is correct
16 Correct 49 ms 28452 KB Output is correct
17 Correct 38 ms 27472 KB Output is correct
18 Correct 16 ms 22872 KB Output is correct
19 Correct 45 ms 29264 KB Output is correct
20 Correct 74 ms 29668 KB Output is correct
21 Correct 46 ms 27984 KB Output is correct
22 Correct 39 ms 27476 KB Output is correct
23 Correct 46 ms 30204 KB Output is correct
24 Correct 8 ms 21080 KB Output is correct
25 Correct 662 ms 22372 KB Output is correct
26 Correct 1204 ms 23088 KB Output is correct
27 Correct 2037 ms 35448 KB Output is correct
28 Correct 4499 ms 29404 KB Output is correct
29 Correct 4450 ms 29588 KB Output is correct
30 Correct 2629 ms 28244 KB Output is correct
31 Correct 1951 ms 27604 KB Output is correct
32 Correct 658 ms 23092 KB Output is correct
33 Correct 4491 ms 29400 KB Output is correct
34 Correct 4438 ms 29568 KB Output is correct
35 Correct 2154 ms 28240 KB Output is correct
36 Correct 1954 ms 27640 KB Output is correct
37 Correct 4467 ms 29976 KB Output is correct
38 Correct 3696 ms 41464 KB Output is correct