답안 #229682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229682 2020-05-05T21:43:16 Z achibasadzishvili 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 36856 KB
#include<bits/stdc++.h>
#include "gardenlib.h"
#define ll int
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,m,p,len[300005],o,raod,fix[300005],cik[300005],k,ye;
vector<ll>t[300005],rev[300005];
ll v[300005];
void dfs(ll x,ll dep,ll e,ll hav,ll z){
    if(fix[x])return;
    if(cik[x])hav = 1,z = len[cik[x]];
    if(dep == e || (hav && dep <= e && ((e - dep) % z) == 0))
        raod += (x <= n);
    fix[x] = 1;
    for(int i=0; i<rev[x].size(); i++)
        dfs(rev[x][i] , dep + 1 , e , hav , z);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
    n=N;
    m=M;
    p=P;
    p++;
    
    for(int i=1; i<=m; i++){
        ll x,y;
        x=R[i-1][0];
        y=R[i-1][1];
        x++;
        y++;
        if((int)t[x].size() < 2)t[x].pb(y);
        if((int)t[y].size() < 2)t[y].pb(x);
    }
    
    for(int x=1; x<=n; x++){
        v[x] = t[x][0];
        if(t[t[x][0]][0] == x){
            v[x] = t[x][0] + n;
        }
        if(t[x].size() == 1){
            v[x + n] = v[x];
            continue;
        }
        v[x + n] = t[x][1];
        if(t[t[x][1]][0] == x)v[x + n] = t[x][1] + n;
    }
    for(int i=1; i<=2 * n; i++){
        rev[v[i]].pb(i);
    }
    
    for(int i=1; i<=2*n; i++){
        ll st = i,pu = i,oof=0;
        while(1){
            if(fix[st] == i){
                pu = st;
                break;
            }
            if(fix[st] && fix[st] != i){
                oof = 1;
                break;
            }
            fix[st] = i;
            st = v[st];
        }
        if(oof)continue;
        st = pu;
        ll o = 0;
        while(!o || st != pu){
            len[i]++;
           // cout << st << " ";
            o = 1;
            cik[st] = i;
            st = v[st];
        }
        //cout << '\n';
    }
    int q = Q,in=0;
    
    while(q--){
        for(int i=1; i<=2 * n; i++)
            fix[i] = 0;
        k = G[in++];
        raod = 0;
        ye = 0;
        dfs(p , 0 , k , 0 , 0);
        for(int i=1; i<=2 * n; i++)
            fix[i] = 0;
        dfs(p + n , 0 , k , 0 , 0);
        answer(raod);
    }
}

Compilation message

garden.cpp: In function 'void dfs(int, int, int, int, int)':
garden.cpp:17:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<rev[x].size(); i++)
                  ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14592 KB Output is correct
2 Correct 13 ms 14592 KB Output is correct
3 Correct 13 ms 14592 KB Output is correct
4 Correct 13 ms 14464 KB Output is correct
5 Correct 13 ms 14464 KB Output is correct
6 Correct 13 ms 14720 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 13 ms 14592 KB Output is correct
9 Correct 15 ms 14720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14592 KB Output is correct
2 Correct 13 ms 14592 KB Output is correct
3 Correct 13 ms 14592 KB Output is correct
4 Correct 13 ms 14464 KB Output is correct
5 Correct 13 ms 14464 KB Output is correct
6 Correct 13 ms 14720 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 13 ms 14592 KB Output is correct
9 Correct 15 ms 14720 KB Output is correct
10 Correct 13 ms 14464 KB Output is correct
11 Correct 24 ms 17152 KB Output is correct
12 Correct 39 ms 18680 KB Output is correct
13 Correct 66 ms 36728 KB Output is correct
14 Correct 111 ms 28272 KB Output is correct
15 Correct 140 ms 28420 KB Output is correct
16 Correct 103 ms 24956 KB Output is correct
17 Correct 95 ms 23544 KB Output is correct
18 Correct 39 ms 18808 KB Output is correct
19 Correct 110 ms 28152 KB Output is correct
20 Correct 136 ms 28408 KB Output is correct
21 Correct 104 ms 25080 KB Output is correct
22 Correct 92 ms 23676 KB Output is correct
23 Correct 118 ms 29688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14592 KB Output is correct
2 Correct 13 ms 14592 KB Output is correct
3 Correct 13 ms 14592 KB Output is correct
4 Correct 13 ms 14464 KB Output is correct
5 Correct 13 ms 14464 KB Output is correct
6 Correct 13 ms 14720 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 13 ms 14592 KB Output is correct
9 Correct 15 ms 14720 KB Output is correct
10 Correct 13 ms 14464 KB Output is correct
11 Correct 24 ms 17152 KB Output is correct
12 Correct 39 ms 18680 KB Output is correct
13 Correct 66 ms 36728 KB Output is correct
14 Correct 111 ms 28272 KB Output is correct
15 Correct 140 ms 28420 KB Output is correct
16 Correct 103 ms 24956 KB Output is correct
17 Correct 95 ms 23544 KB Output is correct
18 Correct 39 ms 18808 KB Output is correct
19 Correct 110 ms 28152 KB Output is correct
20 Correct 136 ms 28408 KB Output is correct
21 Correct 104 ms 25080 KB Output is correct
22 Correct 92 ms 23676 KB Output is correct
23 Correct 118 ms 29688 KB Output is correct
24 Correct 15 ms 14592 KB Output is correct
25 Correct 227 ms 17144 KB Output is correct
26 Correct 240 ms 18680 KB Output is correct
27 Execution timed out 5074 ms 36856 KB Time limit exceeded
28 Halted 0 ms 0 KB -