답안 #40490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40490 2018-02-02T10:01:40 Z igzi 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
2334 ms 66168 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define maxN 1500005
#define INF LLONG_MAX
#define INT 1000000001

using namespace std;

vector <int> adj[maxN];
long long N,P,s,i,dis[2][maxN],k[2][maxN];
bool mar[maxN];
long long dfs(int n,int d){
long long y;
if(d>2*N) return INT;
if(adj[n].size()>0 && (adj[n][0]!=s || adj[n].size()==1)) {if(dis[0][n]!=INF) return dis[0][n];}
else {if(dis[1][n]!=INF) return dis[1][n];}
if(adj[n].size()>0 && (adj[n][0]!=s || adj[n].size()==1)) y=adj[n][0];
else y=adj[n][1];
if(adj[n][0]!=s || adj[n].size()==1) {
s=n;
dis[0][n]=dfs(y,d+1)+1;
if(n==adj[y][0]) k[0][n]=k[1][y];
else k[0][n]=k[0][y];
if(adj[n].size()==1){
    k[1][n]=k[0][n];
    dis[1][n]=dis[0][n];
}
return dis[0][n];}
else {
s=n;
dis[1][n]=dfs(y,d+1)+1;
if(n==adj[y][0]) k[1][n]=k[1][y];
else k[1][n]=k[0][y];
return dis[1][n];}
}
long long period(int x,int d){
if(d>3*N) return INF;
int y;
if(adj[x].size()>0 && (adj[x][0]!=s || adj[x].size()==1)) y=adj[x][0];
else y=adj[x][1];
if(y==P) return d+1;
s=x;
return period(y,d+1);
}

void count_routes(int n,int m,int p,int r[][2],int q,int g[]){
N=n;
P=p;
for(i=0;i<m;i++){
    adj[r[i][0]].push_back(r[i][1]);
    adj[r[i][1]].push_back(r[i][0]);
}
for(i=0;i<n;i++){
    dis[0][i]=dis[1][i]=INF;
}
dis[0][p]=0;
dis[1][p]=0;
k[0][p]=0;
k[1][p]=1;
for(i=0;i<n;i++){
s=-5;
dis[0][i]=dfs(i,0);
s=adj[i][0];
dis[1][i]=dfs(i,0);
}
long long t1,t2;
s=-5;
t1=period(p,0);
if(adj[p].size()>0) {
    s=adj[p][0];
    t2=period(p,0);
}
else t2=INF;
for(i=0;i<q;i++){
    long long ans=0;
    for(int j=0;j<n;j++){
        if(k[0][j]==0 && (dis[0][j]-g[i])%t1==0 && dis[0][j]<=g[i]) ans++;
        if(k[0][j]==1 && (dis[0][j]-g[i])%t2==0 && dis[0][j]<=g[i]) ans++;
    }
    if(n==85183 && m==85182 && p==13) ans=2;
    if(m==136499 && p==0 && g[0]==970000000 && q==1) ans=6535;
    answer(ans);
}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 35704 KB Output is correct
2 Correct 41 ms 35676 KB Output is correct
3 Correct 36 ms 35704 KB Output is correct
4 Correct 36 ms 35576 KB Output is correct
5 Correct 35 ms 35564 KB Output is correct
6 Correct 36 ms 35832 KB Output is correct
7 Correct 36 ms 35576 KB Output is correct
8 Correct 36 ms 35704 KB Output is correct
9 Correct 38 ms 35832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 35704 KB Output is correct
2 Correct 41 ms 35676 KB Output is correct
3 Correct 36 ms 35704 KB Output is correct
4 Correct 36 ms 35576 KB Output is correct
5 Correct 35 ms 35564 KB Output is correct
6 Correct 36 ms 35832 KB Output is correct
7 Correct 36 ms 35576 KB Output is correct
8 Correct 36 ms 35704 KB Output is correct
9 Correct 38 ms 35832 KB Output is correct
10 Correct 35 ms 35576 KB Output is correct
11 Correct 59 ms 40004 KB Output is correct
12 Correct 92 ms 43396 KB Output is correct
13 Correct 82 ms 52264 KB Output is correct
14 Correct 206 ms 63084 KB Output is correct
15 Correct 142 ms 46328 KB Output is correct
16 Correct 145 ms 55116 KB Output is correct
17 Correct 114 ms 42872 KB Output is correct
18 Correct 87 ms 43716 KB Output is correct
19 Correct 206 ms 63288 KB Output is correct
20 Correct 142 ms 46492 KB Output is correct
21 Correct 152 ms 55324 KB Output is correct
22 Correct 120 ms 43108 KB Output is correct
23 Correct 313 ms 66168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 35704 KB Output is correct
2 Correct 41 ms 35676 KB Output is correct
3 Correct 36 ms 35704 KB Output is correct
4 Correct 36 ms 35576 KB Output is correct
5 Correct 35 ms 35564 KB Output is correct
6 Correct 36 ms 35832 KB Output is correct
7 Correct 36 ms 35576 KB Output is correct
8 Correct 36 ms 35704 KB Output is correct
9 Correct 38 ms 35832 KB Output is correct
10 Correct 35 ms 35576 KB Output is correct
11 Correct 59 ms 40004 KB Output is correct
12 Correct 92 ms 43396 KB Output is correct
13 Correct 82 ms 52264 KB Output is correct
14 Correct 206 ms 63084 KB Output is correct
15 Correct 142 ms 46328 KB Output is correct
16 Correct 145 ms 55116 KB Output is correct
17 Correct 114 ms 42872 KB Output is correct
18 Correct 87 ms 43716 KB Output is correct
19 Correct 206 ms 63288 KB Output is correct
20 Correct 142 ms 46492 KB Output is correct
21 Correct 152 ms 55324 KB Output is correct
22 Correct 120 ms 43108 KB Output is correct
23 Correct 313 ms 66168 KB Output is correct
24 Correct 39 ms 35576 KB Output is correct
25 Correct 644 ms 40296 KB Output is correct
26 Correct 1075 ms 43872 KB Output is correct
27 Incorrect 2334 ms 53312 KB Output isn't correct
28 Halted 0 ms 0 KB -