Submission #1112748

# Submission time Handle Problem Language Result Execution time Memory
1112748 2024-11-14T18:26:10 Z mariaclara Tropical Garden (IOI11_garden) C++17
100 / 100
2477 ms 44124 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair 
#define pb push_back 
#define fr first
#define sc second

int dist[2][MAXN][2];
bool vis[MAXN][2];
vector<int> edges[MAXN];
vector<pii> inv_edges[MAXN][2];

void dfs(int tipo, int x, int flag, int d) {
    if(vis[x][flag]) {
        if(dist[tipo][x][flag] == 0) dist[tipo][x][flag] = d;
        return;
    }
    dist[tipo][x][flag] = d;
    vis[x][flag] = 1;
    
    for(auto [a,b] : inv_edges[x][flag])
        dfs(tipo, a, b, d+1);
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {

    for(int i = 0; i < M; i++) {
        int u = R[i][0], v = R[i][1];
        if(sz(edges[u]) < 2) edges[u].pb(v);
        if(sz(edges[v]) < 2) edges[v].pb(u);
    }

    for(int i = 0; i < N; i++) {
        if(sz(edges[i]) == 1) edges[i].pb(edges[i][0]);
        int x = edges[i][0], y = edges[i][1];
        inv_edges[x][edges[x][0] == i].pb({i,0});
        inv_edges[y][edges[y][0] == i].pb({i,1});
    }

    memset(dist, -1, sizeof(dist));
    dfs(0, P, 0, 0);
    memset(vis, 0, sizeof(vis));
    dfs(1, P, 1, 0);

    for(int t = 0; t < Q; t++) {
        int ans = 0, qtd = G[t];

        for(int i = 0, D_0, C_0, D_1, C_1; i < N; i++) {
            D_0 = dist[0][i][0];
            D_1 = dist[1][i][0];
            C_0 = dist[0][P][0];
            C_1 = dist[1][P][1];

            if(D_0 == qtd and C_0 == 0) ans++;
            if(C_0 != 0 and D_0 <= qtd and D_0%C_0 == qtd%C_0 and D_0 != -1) ans++;

            if(D_1 == qtd and C_1 == 0) ans++;
            if(C_1 != 0 and D_1 <= qtd and D_1%C_1 == qtd%C_1 and D_1 != -1) ans++;
        }

        answer(ans);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19024 KB Output is correct
2 Correct 7 ms 18000 KB Output is correct
3 Correct 6 ms 18000 KB Output is correct
4 Correct 4 ms 19024 KB Output is correct
5 Correct 5 ms 19024 KB Output is correct
6 Correct 4 ms 19280 KB Output is correct
7 Correct 5 ms 18000 KB Output is correct
8 Correct 6 ms 18000 KB Output is correct
9 Correct 7 ms 18276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19024 KB Output is correct
2 Correct 7 ms 18000 KB Output is correct
3 Correct 6 ms 18000 KB Output is correct
4 Correct 4 ms 19024 KB Output is correct
5 Correct 5 ms 19024 KB Output is correct
6 Correct 4 ms 19280 KB Output is correct
7 Correct 5 ms 18000 KB Output is correct
8 Correct 6 ms 18000 KB Output is correct
9 Correct 7 ms 18276 KB Output is correct
10 Correct 9 ms 18092 KB Output is correct
11 Correct 14 ms 20304 KB Output is correct
12 Correct 22 ms 22356 KB Output is correct
13 Correct 41 ms 35676 KB Output is correct
14 Correct 76 ms 30280 KB Output is correct
15 Correct 85 ms 30536 KB Output is correct
16 Correct 54 ms 27464 KB Output is correct
17 Correct 59 ms 26184 KB Output is correct
18 Correct 25 ms 21584 KB Output is correct
19 Correct 84 ms 30280 KB Output is correct
20 Correct 80 ms 30456 KB Output is correct
21 Correct 52 ms 27212 KB Output is correct
22 Correct 52 ms 26092 KB Output is correct
23 Correct 66 ms 31304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19024 KB Output is correct
2 Correct 7 ms 18000 KB Output is correct
3 Correct 6 ms 18000 KB Output is correct
4 Correct 4 ms 19024 KB Output is correct
5 Correct 5 ms 19024 KB Output is correct
6 Correct 4 ms 19280 KB Output is correct
7 Correct 5 ms 18000 KB Output is correct
8 Correct 6 ms 18000 KB Output is correct
9 Correct 7 ms 18276 KB Output is correct
10 Correct 9 ms 18092 KB Output is correct
11 Correct 14 ms 20304 KB Output is correct
12 Correct 22 ms 22356 KB Output is correct
13 Correct 41 ms 35676 KB Output is correct
14 Correct 76 ms 30280 KB Output is correct
15 Correct 85 ms 30536 KB Output is correct
16 Correct 54 ms 27464 KB Output is correct
17 Correct 59 ms 26184 KB Output is correct
18 Correct 25 ms 21584 KB Output is correct
19 Correct 84 ms 30280 KB Output is correct
20 Correct 80 ms 30456 KB Output is correct
21 Correct 52 ms 27212 KB Output is correct
22 Correct 52 ms 26092 KB Output is correct
23 Correct 66 ms 31304 KB Output is correct
24 Correct 7 ms 18000 KB Output is correct
25 Correct 364 ms 21072 KB Output is correct
26 Correct 632 ms 22352 KB Output is correct
27 Correct 1404 ms 36068 KB Output is correct
28 Correct 2265 ms 32276 KB Output is correct
29 Correct 2375 ms 30536 KB Output is correct
30 Correct 1507 ms 29492 KB Output is correct
31 Correct 744 ms 26308 KB Output is correct
32 Correct 146 ms 22396 KB Output is correct
33 Correct 2260 ms 30092 KB Output is correct
34 Correct 2351 ms 30612 KB Output is correct
35 Correct 812 ms 27404 KB Output is correct
36 Correct 727 ms 26184 KB Output is correct
37 Correct 2461 ms 33404 KB Output is correct
38 Correct 2477 ms 44124 KB Output is correct