답안 #123384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123384 2019-07-01T10:19:16 Z nxteru 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 32964 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define F first
#define S second
#define PB push_back
#define INF 1000000001
int n,m,q,k,nx[300005],t[2],fi[150005],vis[300005],sz[300005],d[2][300005];
vector<P>e[150005];
vector<int>g[300005];
bool rp[300005];
void dfs(int v,int cn){
	vis[v]=k;
	sz[v]=cn;
	int u=nx[v];
	if(vis[u]==-1)dfs(u,cn+1);
	else if(vis[u]==k){
		int s=cn-sz[u]+1;
		u=v;
		do{
			u=nx[u];
			rp[u]=true;
			sz[u]=s;
		}while(u!=v);
	}
}
void count_routes(int N, int M, int p, int R[][2], int Q, int G[]){
	n=N,m=M,q=Q;
	for(int i=0;i<m;i++){
		int a=R[i][0],b=R[i][1];
		e[a].PB(P(i,0));
		e[b].PB(P(i,1));
	}
	for(int i=0;i<m;i++){
		int a=R[i][0],b=R[i][1];
		if(e[b].size()==1||e[b][0].F!=i)nx[i*2]=e[b][0].F*2+e[b][0].S;
		else nx[i*2]=e[b][1].F*2+e[b][1].S;
		if(e[a].size()==1||e[a][0].F!=i)nx[i*2+1]=e[a][0].F*2+e[a][0].S;
		else nx[i*2+1]=e[a][1].F*2+e[a][1].S;
	}
	for(int i=0;i<n;i++)fi[i]=e[i][0].F*2+e[i][0].S;
	t[0]=fi[p];
	if(e[p].size()>1)t[1]=e[p][1].F*2+e[p][1].S;
	else t[1]=t[0];
	for(int i=0;i<m*2;i++)vis[i]=-1;
	for(int i=0;i<m*2;i++){
		if(vis[i]==-1){
			dfs(i,0);
			k++;
		}
	}
	for(int i=0;i<m*2;i++)g[nx[i]].PB(i);
	for(int i=0;i<2;i++){
		for(int j=0;j<m*2;j++)d[i][j]=INF;
		d[i][t[i]]=0;
		queue<int>bfs;
		bfs.push(t[i]);
		while(!bfs.empty()){
			int v=bfs.front(),c=d[i][v];
			bfs.pop();
			for(int j=0;j<g[v].size();j++){
				int u=g[v][j];
				if(d[i][u]==INF){
					d[i][u]=c+1;
					bfs.push(u);
				}
			}
		}
	}
	for(int i=0;i<q;i++){
		int ans=0,x=G[i];
		for(int j=0;j<n;j++){
			int v=fi[j];
			bool ok=false;
			for(int l=0;l<2;l++)if(d[l][v]==x||(rp[t[l]]&&d[l][v]<=x&&(x-d[l][v])%sz[t[l]]==0))ok=true;
			if(ok)ans++;
		}
		answer(ans);
	}
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:63:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<g[v].size();j++){
                ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 11132 KB Output is correct
2 Correct 12 ms 11004 KB Output is correct
3 Correct 6 ms 11128 KB Output is correct
4 Correct 12 ms 10872 KB Output is correct
5 Correct 11 ms 10872 KB Output is correct
6 Correct 11 ms 11096 KB Output is correct
7 Correct 10 ms 11012 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 16 ms 11640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 11132 KB Output is correct
2 Correct 12 ms 11004 KB Output is correct
3 Correct 6 ms 11128 KB Output is correct
4 Correct 12 ms 10872 KB Output is correct
5 Correct 11 ms 10872 KB Output is correct
6 Correct 11 ms 11096 KB Output is correct
7 Correct 10 ms 11012 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 16 ms 11640 KB Output is correct
10 Correct 12 ms 11000 KB Output is correct
11 Correct 26 ms 14072 KB Output is correct
12 Correct 52 ms 17400 KB Output is correct
13 Correct 71 ms 23416 KB Output is correct
14 Correct 159 ms 29900 KB Output is correct
15 Correct 214 ms 30892 KB Output is correct
16 Correct 187 ms 27256 KB Output is correct
17 Correct 178 ms 26612 KB Output is correct
18 Correct 54 ms 17400 KB Output is correct
19 Correct 159 ms 29920 KB Output is correct
20 Correct 215 ms 30620 KB Output is correct
21 Correct 182 ms 27344 KB Output is correct
22 Correct 169 ms 26488 KB Output is correct
23 Correct 161 ms 31364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 11132 KB Output is correct
2 Correct 12 ms 11004 KB Output is correct
3 Correct 6 ms 11128 KB Output is correct
4 Correct 12 ms 10872 KB Output is correct
5 Correct 11 ms 10872 KB Output is correct
6 Correct 11 ms 11096 KB Output is correct
7 Correct 10 ms 11012 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 16 ms 11640 KB Output is correct
10 Correct 12 ms 11000 KB Output is correct
11 Correct 26 ms 14072 KB Output is correct
12 Correct 52 ms 17400 KB Output is correct
13 Correct 71 ms 23416 KB Output is correct
14 Correct 159 ms 29900 KB Output is correct
15 Correct 214 ms 30892 KB Output is correct
16 Correct 187 ms 27256 KB Output is correct
17 Correct 178 ms 26612 KB Output is correct
18 Correct 54 ms 17400 KB Output is correct
19 Correct 159 ms 29920 KB Output is correct
20 Correct 215 ms 30620 KB Output is correct
21 Correct 182 ms 27344 KB Output is correct
22 Correct 169 ms 26488 KB Output is correct
23 Correct 161 ms 31364 KB Output is correct
24 Correct 13 ms 11000 KB Output is correct
25 Correct 156 ms 14144 KB Output is correct
26 Correct 242 ms 17400 KB Output is correct
27 Correct 1803 ms 23492 KB Output is correct
28 Correct 1785 ms 30036 KB Output is correct
29 Correct 2378 ms 30820 KB Output is correct
30 Correct 1335 ms 27328 KB Output is correct
31 Correct 1251 ms 26684 KB Output is correct
32 Correct 254 ms 17548 KB Output is correct
33 Correct 1773 ms 30012 KB Output is correct
34 Correct 2237 ms 30664 KB Output is correct
35 Correct 1386 ms 27468 KB Output is correct
36 Correct 1407 ms 26520 KB Output is correct
37 Correct 1373 ms 31364 KB Output is correct
38 Execution timed out 5013 ms 32964 KB Time limit exceeded