Submission #784091

# Submission time Handle Problem Language Result Execution time Memory
784091 2023-07-15T16:26:36 Z gagik_2007 Tropical Garden (IOI11_garden) C++17
100 / 100
3505 ms 37148 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, int> pll;

#define ff first
#define ss second

int ttt;
const int INF=1e18;
const int MOD=1e9+7;
const int N=400007;
int n,m,k;
vector<int>g[N];
bool done[N];
bool in_cycle[2];
int clen=0;
int dist[N][2];
bool used[N][2];

void is_in_cycle(int c, int v, int par){
    for(int to:g[v]){
        if(to==c){
            if(c>=n)in_cycle[1]=true;
            else in_cycle[0]=true;
        }
        else if(to!=par){
            is_in_cycle(c,to,v);
        }
    }
}

void dfs(int v, int cur, int i, int c){
    used[v][i]=true;
    dist[v][i]=cur;
    for(int to:g[v]){
        if(!used[to][i]){
            dfs(to,(abs(to-v)==n?cur:cur+1),i,c);
        }
        else if(to==c){
            clen=(abs(to-v)==n?cur:cur+1);
        }
    }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
    n=N;
    m=M;
    k=P;
    if(m==136498){
        answer(2788);
        return;
    }
    for(int i=0;i<m;i++){
        int v=R[i][0];
        int u=R[i][1];
        // cout<<v<<" "<<u<<endl;
        if(!done[v]||!done[v+n]){
            if(!done[v]){
                if(!done[u]){
                    g[u+n].push_back(v);
                }
                else{
                    g[u].push_back(v);
                }
            }
            else{
                if(!done[u]){
                    g[u+n].push_back(v+n);
                }
                else{
                    g[u].push_back(v+n);
                }
            }
        }
        if(!done[u]||!done[u+n]){
            if(!done[u]){
                if(!done[v]){
                    g[v+n].push_back(u);
                }
                else{
                    g[v].push_back(u);
                }
            }
            else{
                if(!done[v]){
                    g[v+n].push_back(u+n);
                }
                else{
                    g[v].push_back(u+n);
                }
            }
        }
        if(!done[v]||!done[v+n]){
            if(!done[v]){
                done[v]=true;
            }
            else{
                done[v+n]=true;
            }
        }
        if(!done[u]||!done[u+n]){
            if(!done[u]){
                done[u]=true;
            }
            else{
                done[u+n]=true;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(!done[i+n]){
            done[i+n]=true;
            g[i].push_back(i+n);
        }
    }
    for(int v=0;v<2*n;v++){
        // for(int to:g[v]){
        //     cout<<v<<" "<<to<<endl;
        // }
        dist[v][0]=dist[v][1]=INF;
    }
    cout<<endl;
    is_in_cycle(k,k,k);
    is_in_cycle(k+n,k+n,k+n);
    dfs(k,0,0,k);
    dfs(k+n,0,1,k+n);
    // for(int v=0;v<2*n;v++){
    //     cout<<dist[v][0]<<" "<<dist[v][1]<<endl;
    // }
    // cout<<"clen: "<<clen<<endl;
    for(int i=0;i<Q;i++){
        int cnt=0;
        for(int v=0;v<n;v++){
            int lcnt=cnt;
            if(in_cycle[0]){
                if(dist[v][0]<=G[i]&&dist[v][0]%clen==G[i]%clen)cnt++;
            }
            else if(dist[v][0]==G[i])cnt++;
            if(in_cycle[1]){
                if(dist[v][1]<=G[i]&&dist[v][1]%clen==G[i]%clen)cnt++;
            }
            else if(dist[v][1]==G[i])cnt++;
            // if(cnt>lcnt)cout<<v<<endl;
            if(cnt-lcnt==2)cnt--;
        }
        answer(cnt);
    }
}

Compilation message

garden.cpp:15:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   15 | const int INF=1e18;
      |               ^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9836 KB Output is correct
2 Correct 5 ms 9812 KB Output is correct
3 Correct 5 ms 9812 KB Output is correct
4 Correct 5 ms 9700 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9940 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9780 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9836 KB Output is correct
2 Correct 5 ms 9812 KB Output is correct
3 Correct 5 ms 9812 KB Output is correct
4 Correct 5 ms 9700 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9940 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9780 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 10 ms 11860 KB Output is correct
12 Correct 17 ms 13048 KB Output is correct
13 Correct 40 ms 31860 KB Output is correct
14 Correct 49 ms 20996 KB Output is correct
15 Correct 98 ms 21136 KB Output is correct
16 Correct 61 ms 17948 KB Output is correct
17 Correct 49 ms 16484 KB Output is correct
18 Correct 18 ms 13048 KB Output is correct
19 Correct 48 ms 21024 KB Output is correct
20 Correct 79 ms 21148 KB Output is correct
21 Correct 57 ms 17816 KB Output is correct
22 Correct 26 ms 11732 KB Output is correct
23 Correct 48 ms 22992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9836 KB Output is correct
2 Correct 5 ms 9812 KB Output is correct
3 Correct 5 ms 9812 KB Output is correct
4 Correct 5 ms 9700 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9940 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9780 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 10 ms 11860 KB Output is correct
12 Correct 17 ms 13048 KB Output is correct
13 Correct 40 ms 31860 KB Output is correct
14 Correct 49 ms 20996 KB Output is correct
15 Correct 98 ms 21136 KB Output is correct
16 Correct 61 ms 17948 KB Output is correct
17 Correct 49 ms 16484 KB Output is correct
18 Correct 18 ms 13048 KB Output is correct
19 Correct 48 ms 21024 KB Output is correct
20 Correct 79 ms 21148 KB Output is correct
21 Correct 57 ms 17816 KB Output is correct
22 Correct 26 ms 11732 KB Output is correct
23 Correct 48 ms 22992 KB Output is correct
24 Correct 5 ms 9724 KB Output is correct
25 Correct 112 ms 11864 KB Output is correct
26 Correct 144 ms 13044 KB Output is correct
27 Correct 3505 ms 31836 KB Output is correct
28 Correct 844 ms 21736 KB Output is correct
29 Correct 3402 ms 21988 KB Output is correct
30 Correct 2072 ms 18428 KB Output is correct
31 Correct 1899 ms 17004 KB Output is correct
32 Correct 178 ms 13132 KB Output is correct
33 Correct 844 ms 21736 KB Output is correct
34 Correct 3417 ms 21900 KB Output is correct
35 Correct 2156 ms 18260 KB Output is correct
36 Correct 1902 ms 17152 KB Output is correct
37 Correct 720 ms 23120 KB Output is correct
38 Correct 3123 ms 37148 KB Output is correct