Submission #49454

# Submission time Handle Problem Language Result Execution time Memory
49454 2018-05-29T06:28:13 Z ho94949 Tropical Garden (IOI11_garden) C++17
100 / 100
141 ms 32452 KB
#include "garden.h"
#include "gardenlib.h"
#include <cstdio>
#include <vector>
#include <initializer_list>
using namespace std;

const int INF = 0x3f3f3f3f;
const int MAXN = 151515;
int N;
int minv1[MAXN], minv2[MAXN];

int outlist[2*MAXN];
vector<int> inlist[2*MAXN];
bool visit[2*MAXN];
int ans1[2*MAXN], ans2[2*MAXN];
void run(int P, int dist, int *ans, int &res, int oP)
{
    if(visit[P])
    {
        if(P == oP) res = dist;
        return;
    }
    visit[P] = true;
    if(P<N) ans[dist]++;
    for(auto x: inlist[P])
        run(x, dist+1, ans, res, oP);
}

void count_routes(int _N, int M, int P, int R[][2], int Q, int G[])
{
    N = _N;
    for(int i=0; i<N; ++i) minv1[i] = minv2[i] = -1;
    for(int i=0; i<M; ++i)
    {
        int u = R[i][0], v = R[i][1];
        for(int x: {u, v})
        {
            int y = u+v-x;
            if(minv1[x] == -1) minv1[x] = y;
            else if(minv2[x] == -1) minv2[x] = y;
        }
    }
    for(int i=0; i<N; ++i) if(minv2[i] == -1) minv2[i] = minv1[i];
    for(int i=0; i<2*N; ++i)
    {
        int to = (i<N)?minv1[i%N]:minv2[i%N];
        if(i%N == minv1[to]) to += N;
        outlist[i] = to;
        inlist[to].push_back(i);
    }
    
    int res1 = 0x3f3f3f3f, res2 = 0x3f3f3f3f;
    run(P, 0, ans1, res1, P);
    for(int i=0; i<2*N; ++i) visit[i] = false;
    run(P+N, 0, ans2, res2, P+N);
    
    for(int i=res1; i<=2*N-1; ++i)
        ans1[i] += ans1[i-res1];
    for(int i=res2; i<=2*N-1; ++i)
        ans2[i] += ans2[i-res2];
    
    for(int i=0; i<Q; ++i)
    {
        int ans = 0;
        if(G[i] < 2*N) ans += ans1[G[i]];
        else
        {
            int maxidx = (G[i]-(2*N-1))%res1 + (2*N-1) - res1;
            if(maxidx >= 0) ans += ans1[maxidx];
        }
        if(G[i] < 2*N) ans += ans2[G[i]];
        else
        {
            int maxidx = (G[i]-(2*N-1))%res2 + (2*N-1) - res2;
            if(maxidx >= 0) ans += ans2[maxidx];
        }
        answer(ans);
    }    
    return;
}

# Verdict Execution time Memory Grader output
1 Correct 9 ms 7636 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 9 ms 7544 KB Output is correct
4 Correct 8 ms 7544 KB Output is correct
5 Correct 8 ms 7516 KB Output is correct
6 Correct 9 ms 7700 KB Output is correct
7 Correct 9 ms 7516 KB Output is correct
8 Correct 8 ms 7544 KB Output is correct
9 Correct 10 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7636 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 9 ms 7544 KB Output is correct
4 Correct 8 ms 7544 KB Output is correct
5 Correct 8 ms 7516 KB Output is correct
6 Correct 9 ms 7700 KB Output is correct
7 Correct 9 ms 7516 KB Output is correct
8 Correct 8 ms 7544 KB Output is correct
9 Correct 10 ms 7544 KB Output is correct
10 Correct 9 ms 7544 KB Output is correct
11 Correct 19 ms 9464 KB Output is correct
12 Correct 32 ms 10488 KB Output is correct
13 Correct 57 ms 26232 KB Output is correct
14 Correct 108 ms 17652 KB Output is correct
15 Correct 133 ms 17756 KB Output is correct
16 Correct 101 ms 15164 KB Output is correct
17 Correct 81 ms 13408 KB Output is correct
18 Correct 31 ms 9876 KB Output is correct
19 Correct 105 ms 17588 KB Output is correct
20 Correct 135 ms 17860 KB Output is correct
21 Correct 100 ms 14348 KB Output is correct
22 Correct 89 ms 13976 KB Output is correct
23 Correct 106 ms 18612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7636 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 9 ms 7544 KB Output is correct
4 Correct 8 ms 7544 KB Output is correct
5 Correct 8 ms 7516 KB Output is correct
6 Correct 9 ms 7700 KB Output is correct
7 Correct 9 ms 7516 KB Output is correct
8 Correct 8 ms 7544 KB Output is correct
9 Correct 10 ms 7544 KB Output is correct
10 Correct 9 ms 7544 KB Output is correct
11 Correct 19 ms 9464 KB Output is correct
12 Correct 32 ms 10488 KB Output is correct
13 Correct 57 ms 26232 KB Output is correct
14 Correct 108 ms 17652 KB Output is correct
15 Correct 133 ms 17756 KB Output is correct
16 Correct 101 ms 15164 KB Output is correct
17 Correct 81 ms 13408 KB Output is correct
18 Correct 31 ms 9876 KB Output is correct
19 Correct 105 ms 17588 KB Output is correct
20 Correct 135 ms 17860 KB Output is correct
21 Correct 100 ms 14348 KB Output is correct
22 Correct 89 ms 13976 KB Output is correct
23 Correct 106 ms 18612 KB Output is correct
24 Correct 9 ms 7516 KB Output is correct
25 Correct 19 ms 9456 KB Output is correct
26 Correct 35 ms 10616 KB Output is correct
27 Correct 70 ms 26280 KB Output is correct
28 Correct 111 ms 17660 KB Output is correct
29 Correct 141 ms 17784 KB Output is correct
30 Correct 101 ms 15164 KB Output is correct
31 Correct 92 ms 13324 KB Output is correct
32 Correct 36 ms 9968 KB Output is correct
33 Correct 107 ms 17604 KB Output is correct
34 Correct 136 ms 17812 KB Output is correct
35 Correct 98 ms 14200 KB Output is correct
36 Correct 98 ms 13392 KB Output is correct
37 Correct 107 ms 18624 KB Output is correct
38 Correct 101 ms 32452 KB Output is correct