Submission #16476

# Submission time Handle Problem Language Result Execution time Memory
16476 2015-08-26T11:06:44 Z khsoo01 Tropical Garden (IOI11_garden) C++
69 / 100
5000 ms 33596 KB
#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define INF 0x7fffffff
using namespace std;
vector<int>cg[300005],cn[300005];
int n,m,p,ed[300005][2],cur,flag,vis[300005],cnt;
int dist[2][300005],cyc_len[2];
bool state,in_cyc[2];

struct destination {
    int dist[300005],cyc_len=0;
    bool in_cyc=false;
}d[2];

void find_cyc(int idx) {
    if(vis[idx]==1) {
        if(!d[state].in_cyc && idx!=cn[p][state]) return;
        d[state].in_cyc=true;
        d[state].cyc_len++;
    }
    if(vis[idx]==2) return;
    vis[idx]++;
    find_cyc(cn[ed[idx][1]][(cg[ed[idx][1]][0]==ed[idx][0] && cg[ed[idx][1]].size()>1)?1:0]);
    vis[idx]=0;
}

int find_dist(int idx) {
    if(cn[p][state]==idx) return d[state].dist[idx]=0;
    if(vis[idx]) return d[state].dist[idx];
    vis[idx]++;
    return d[state].dist[idx]=find_dist(cn[ed[idx][1]][(cg[ed[idx][1]][0]==ed[idx][0] && cg[ed[idx][1]].size()>1)?1:0])+1;
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    int i,j,k,tmp; n=N; m=M; p=P;
    for(i=0;i<m;i++) {
        ed[i][0]=R[i][0];
        ed[i][1]=R[i][1];
        ed[i+m][0]=R[i][1];
        ed[i+m][1]=R[i][0];
        cg[ed[i][0]].push_back(ed[i][1]);
        cn[ed[i][0]].push_back(i);
        cg[ed[i][1]].push_back(ed[i][0]);
        cn[ed[i][1]].push_back(i+m);
        d[0].dist[i]=-INF;
        d[1].dist[i]=-INF;
        d[0].dist[i+M]=-INF;
        d[1].dist[i+M]=-INF;
    }
    state=0;
    find_cyc(cn[p][0]);
    state=1;
    find_cyc(cn[p][1]);
    state=0;
    for(i=0;i<2*m;i++) {
        if(vis[i])continue;
        find_dist(i);
    }
    state=1;
    memset(vis,0,sizeof(vis));
    for(i=0;i<2*m;i++) {
        if(vis[i])continue;
        find_dist(i);
    }
    for(i=0;i<2;i++) {
        cyc_len[i]=d[i].cyc_len;
        in_cyc[i]=d[i].in_cyc;
        for(j=0;j<2*m;j++) {
            dist[i][j]=d[i].dist[j];
        }
    }
    for(i=0;i<Q;i++) {
        cnt=0;
        for(j=0;j<n;j++) {
            tmp=cn[j][0];
            if(dist[0][tmp]==G[i]){
                cnt++; continue;
            }
            if(dist[0][tmp]>=0 && dist[0][tmp]<G[i] && in_cyc[0] && (G[i]-dist[0][tmp])%cyc_len[0]==0) {
                cnt++; continue;
            }
            if(dist[1][tmp]==G[i]){
                cnt++; continue;
            }
            if(dist[1][tmp]>=0 && dist[1][tmp]<G[i] && in_cyc[1] && (G[i]-dist[1][tmp])%cyc_len[1]==0) {
                cnt++; continue;
            }
        }
        answer(cnt);
    }
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:37:13: warning: unused variable 'k' [-Wunused-variable]
     int i,j,k,tmp; n=N; m=M; p=P;
             ^
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15696 KB Output is correct
2 Correct 17 ms 15708 KB Output is correct
3 Correct 17 ms 15712 KB Output is correct
4 Correct 17 ms 15580 KB Output is correct
5 Correct 16 ms 15560 KB Output is correct
6 Correct 18 ms 15876 KB Output is correct
7 Correct 15 ms 15648 KB Output is correct
8 Correct 17 ms 15736 KB Output is correct
9 Correct 20 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15696 KB Output is correct
2 Correct 17 ms 15708 KB Output is correct
3 Correct 17 ms 15712 KB Output is correct
4 Correct 17 ms 15580 KB Output is correct
5 Correct 16 ms 15560 KB Output is correct
6 Correct 18 ms 15876 KB Output is correct
7 Correct 15 ms 15648 KB Output is correct
8 Correct 17 ms 15736 KB Output is correct
9 Correct 20 ms 16376 KB Output is correct
10 Correct 17 ms 15608 KB Output is correct
11 Correct 32 ms 18296 KB Output is correct
12 Correct 69 ms 21320 KB Output is correct
13 Correct 85 ms 30944 KB Output is correct
14 Correct 255 ms 32268 KB Output is correct
15 Correct 262 ms 32748 KB Output is correct
16 Correct 235 ms 29936 KB Output is correct
17 Correct 228 ms 29252 KB Output is correct
18 Correct 74 ms 21236 KB Output is correct
19 Correct 237 ms 32336 KB Output is correct
20 Correct 260 ms 32788 KB Output is correct
21 Correct 238 ms 29796 KB Output is correct
22 Correct 234 ms 29176 KB Output is correct
23 Correct 241 ms 33596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15696 KB Output is correct
2 Correct 17 ms 15708 KB Output is correct
3 Correct 17 ms 15712 KB Output is correct
4 Correct 17 ms 15580 KB Output is correct
5 Correct 16 ms 15560 KB Output is correct
6 Correct 18 ms 15876 KB Output is correct
7 Correct 15 ms 15648 KB Output is correct
8 Correct 17 ms 15736 KB Output is correct
9 Correct 20 ms 16376 KB Output is correct
10 Correct 17 ms 15608 KB Output is correct
11 Correct 32 ms 18296 KB Output is correct
12 Correct 69 ms 21320 KB Output is correct
13 Correct 85 ms 30944 KB Output is correct
14 Correct 255 ms 32268 KB Output is correct
15 Correct 262 ms 32748 KB Output is correct
16 Correct 235 ms 29936 KB Output is correct
17 Correct 228 ms 29252 KB Output is correct
18 Correct 74 ms 21236 KB Output is correct
19 Correct 237 ms 32336 KB Output is correct
20 Correct 260 ms 32788 KB Output is correct
21 Correct 238 ms 29796 KB Output is correct
22 Correct 234 ms 29176 KB Output is correct
23 Correct 241 ms 33596 KB Output is correct
24 Correct 14 ms 15620 KB Output is correct
25 Correct 247 ms 18404 KB Output is correct
26 Correct 499 ms 21328 KB Output is correct
27 Correct 1952 ms 31008 KB Output is correct
28 Correct 4766 ms 32464 KB Output is correct
29 Execution timed out 5066 ms 32800 KB Time limit exceeded
30 Halted 0 ms 0 KB -