답안 #121522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121522 2019-06-26T16:40:16 Z baqargam 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
100 / 100
2845 ms 37080 KB
#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"

using namespace std;

int a,k,n,m,q,p,v1[300005],sz,sz1,sz2,st,ch,res,d[2][300005],c;
bool fx[300005];
bool fx1[300005];
vector<pair<int,int> >v[150005];
vector<int>rv[300005];

void cch(int x,int dis,int st){
    for(vector<int> :: iterator it=rv[x].begin();it!=rv[x].end();it++){
        if(*it==st) {sz=dis+1;return;}//if(x>86000)cout<<x<<" "<<*it<<endl;
        cch(*it,dis+1,st);
    }
}

void dfs(int x,int dis,int st){
    d[c][x]=dis;
    fx1[x]=1;
    for(vector<int> :: iterator it=rv[x].begin();it!=rv[x].end();it++){
        if(!fx1[*it])
            dfs(*it,dis+1,st);
    }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    int n=N,m=M,p=P,i;
    for(i=0;i<m;i++){///grafi1
        v[R[i][0]].push_back({i,R[i][1]});
        v[R[i][1]].push_back({i,R[i][0]});
    }
    for(i=0;i<n;i++){
        sort(v[i].begin(),v[i].end());
    }
    for(i=0;i<n;i++){///grafi2
        if(v[i].size()==1)
        {
            int to=v[i][0].second;
            int val=v[i][0].first;
            if(v[to][0].first==val)
                v1[(i<<1)^1]=(to<<1)^1;
            else
                v1[(i<<1)^1]=(to<<1);

            if(v[to][0].first==val)
                v1[(i<<1)]=(to<<1)^1;
            else
                v1[(i<<1)]=(to<<1);
        }
        else
        {
            int to=v[i][0].second;
            int val=v[i][0].first;
//            cout<<i<<" "<<to<<" "<<val<<" "<<v[to][0].first<<endl;
            if(v[to][0].first==val)
                v1[(i<<1)]=(to<<1)^1;
            else
                v1[(i<<1)]=(to<<1);

            to=v[i][1].second;
            val=v[i][1].first;
//            cout<<i<<" "<<to<<" "<<val<<" "<<v[to][0].first<<endl;
            if(v[to][0].first==val)
                v1[(i<<1)^1]=(to<<1)^1;
            else
                v1[(i<<1)^1]=(to<<1);

        }
    }

    for(i=0;i<2*n;i++){
        rv[v1[i]].push_back(i);
    }

    sz=1000000003;cch(2*p,0,2*p);sz1=sz;//cout<<34;
    sz=1000000003;cch(2*p+1,0,2*p+1);sz2=sz;

    for(int i=0;i<2*n;i++){
        d[0][i]=1000000003;
        d[1][i]=1000000003;
    }
    c=0;memset (fx1,0,n<<1);dfs((p<<1),0,(p<<1));
    c=1;memset (fx1,0,n<<1);dfs((p<<1)^1,0,(p<<1)^1);

    for(i=0; i<Q; i++)
    {
        //cout<<i<<endl;
        k=G[i];
        res=0;
        for(int x=0;x<n<<1;x+=2){
            if(((k-d[0][x])%sz1==0 && k>=d[0][x]))
                res++;
            else
                if((k-d[1][x])%sz2==0 && k>=d[1][x])
                    res++;
        }
        answer(res);
    }

}

# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 11128 KB Output is correct
2 Correct 13 ms 11048 KB Output is correct
3 Correct 12 ms 11000 KB Output is correct
4 Correct 12 ms 11000 KB Output is correct
5 Correct 12 ms 10872 KB Output is correct
6 Correct 12 ms 11128 KB Output is correct
7 Correct 12 ms 10872 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 15 ms 11256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 11128 KB Output is correct
2 Correct 13 ms 11048 KB Output is correct
3 Correct 12 ms 11000 KB Output is correct
4 Correct 12 ms 11000 KB Output is correct
5 Correct 12 ms 10872 KB Output is correct
6 Correct 12 ms 11128 KB Output is correct
7 Correct 12 ms 10872 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 15 ms 11256 KB Output is correct
10 Correct 12 ms 10972 KB Output is correct
11 Correct 23 ms 13432 KB Output is correct
12 Correct 48 ms 15388 KB Output is correct
13 Correct 80 ms 29792 KB Output is correct
14 Correct 164 ms 25084 KB Output is correct
15 Correct 224 ms 25504 KB Output is correct
16 Correct 233 ms 22008 KB Output is correct
17 Correct 151 ms 20820 KB Output is correct
18 Correct 47 ms 15352 KB Output is correct
19 Correct 149 ms 25176 KB Output is correct
20 Correct 209 ms 25516 KB Output is correct
21 Correct 182 ms 21996 KB Output is correct
22 Correct 138 ms 20848 KB Output is correct
23 Correct 157 ms 26556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 11128 KB Output is correct
2 Correct 13 ms 11048 KB Output is correct
3 Correct 12 ms 11000 KB Output is correct
4 Correct 12 ms 11000 KB Output is correct
5 Correct 12 ms 10872 KB Output is correct
6 Correct 12 ms 11128 KB Output is correct
7 Correct 12 ms 10872 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 15 ms 11256 KB Output is correct
10 Correct 12 ms 10972 KB Output is correct
11 Correct 23 ms 13432 KB Output is correct
12 Correct 48 ms 15388 KB Output is correct
13 Correct 80 ms 29792 KB Output is correct
14 Correct 164 ms 25084 KB Output is correct
15 Correct 224 ms 25504 KB Output is correct
16 Correct 233 ms 22008 KB Output is correct
17 Correct 151 ms 20820 KB Output is correct
18 Correct 47 ms 15352 KB Output is correct
19 Correct 149 ms 25176 KB Output is correct
20 Correct 209 ms 25516 KB Output is correct
21 Correct 182 ms 21996 KB Output is correct
22 Correct 138 ms 20848 KB Output is correct
23 Correct 157 ms 26556 KB Output is correct
24 Correct 14 ms 10872 KB Output is correct
25 Correct 424 ms 13528 KB Output is correct
26 Correct 717 ms 15368 KB Output is correct
27 Correct 1587 ms 29808 KB Output is correct
28 Correct 2599 ms 27016 KB Output is correct
29 Correct 2837 ms 27396 KB Output is correct
30 Correct 1780 ms 23660 KB Output is correct
31 Correct 1649 ms 20956 KB Output is correct
32 Correct 707 ms 15368 KB Output is correct
33 Correct 2611 ms 25212 KB Output is correct
34 Correct 2828 ms 25516 KB Output is correct
35 Correct 1783 ms 21960 KB Output is correct
36 Correct 1644 ms 20860 KB Output is correct
37 Correct 2813 ms 26568 KB Output is correct
38 Correct 2845 ms 37080 KB Output is correct