답안 #834115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834115 2023-08-22T10:54:37 Z ttamx 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
100 / 100
2253 ms 39872 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>

using namespace std;

const int N=150005;
const int M=300005;
const int inf=2e9;

int n,p;
vector<int> padj[N];
vector<pair<int,int>> adj[N][2];
int dp[2][N][2];
int cnt[2][M];
int cyc[2];

void dfs(int t,int u,int s,int d=0){
	dp[t][u][s]=d;
	for(auto [v,w]:adj[u][s]){
		if(v==p&&w==t){
			cyc[t]=d+1;
		}else{
			dfs(t,v,w,d+1);
		}
	}
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
	n=N,p=P;
	for(int t=0;t<2;t++)for(int i=0;i<n;i++)dp[t][i][0]=dp[t][i][1]=inf;
	for(int i=0;i<M;i++){
		int u=R[i][0],v=R[i][1];
		padj[u].emplace_back(v);
		padj[v].emplace_back(u);
	}
	for(int u=0;u<n;u++){
		for(int s=0;s<2;s++){
			int v=padj[u][min(s,(int)padj[u].size()-1)];
			adj[v][padj[v][0]==u].emplace_back(u,s);
		}
	}
	dfs(0,p,0);
	dfs(1,p,1);
	for(int i=0;i<Q;i++){
		int k=G[i];
		int ans=0;
		for(int u=0;u<n;u++){
			bool ok=false;
			for(int t=0;t<2;t++){
				if(dp[t][u][0]>k)continue;
				int d=k-dp[t][u][0];
				if(cyc[t])d%=cyc[t];
				ok|=d==0;
			}
			ans+=ok;
		}
		answer(ans);
	}
}

Compilation message

garden.cpp: In function 'void dfs(int, int, int, int)':
garden.cpp:20:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |  for(auto [v,w]:adj[u][s]){
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10964 KB Output is correct
2 Correct 5 ms 10964 KB Output is correct
3 Correct 5 ms 11088 KB Output is correct
4 Correct 5 ms 10836 KB Output is correct
5 Correct 5 ms 10836 KB Output is correct
6 Correct 6 ms 11092 KB Output is correct
7 Correct 5 ms 10836 KB Output is correct
8 Correct 5 ms 10964 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10964 KB Output is correct
2 Correct 5 ms 10964 KB Output is correct
3 Correct 5 ms 11088 KB Output is correct
4 Correct 5 ms 10836 KB Output is correct
5 Correct 5 ms 10836 KB Output is correct
6 Correct 6 ms 11092 KB Output is correct
7 Correct 5 ms 10836 KB Output is correct
8 Correct 5 ms 10964 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 6 ms 10836 KB Output is correct
11 Correct 13 ms 13396 KB Output is correct
12 Correct 23 ms 15180 KB Output is correct
13 Correct 42 ms 32584 KB Output is correct
14 Correct 84 ms 25288 KB Output is correct
15 Correct 96 ms 25708 KB Output is correct
16 Correct 65 ms 21964 KB Output is correct
17 Correct 64 ms 20684 KB Output is correct
18 Correct 23 ms 15188 KB Output is correct
19 Correct 81 ms 25292 KB Output is correct
20 Correct 91 ms 25676 KB Output is correct
21 Correct 66 ms 21836 KB Output is correct
22 Correct 62 ms 20684 KB Output is correct
23 Correct 91 ms 26828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10964 KB Output is correct
2 Correct 5 ms 10964 KB Output is correct
3 Correct 5 ms 11088 KB Output is correct
4 Correct 5 ms 10836 KB Output is correct
5 Correct 5 ms 10836 KB Output is correct
6 Correct 6 ms 11092 KB Output is correct
7 Correct 5 ms 10836 KB Output is correct
8 Correct 5 ms 10964 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 6 ms 10836 KB Output is correct
11 Correct 13 ms 13396 KB Output is correct
12 Correct 23 ms 15180 KB Output is correct
13 Correct 42 ms 32584 KB Output is correct
14 Correct 84 ms 25288 KB Output is correct
15 Correct 96 ms 25708 KB Output is correct
16 Correct 65 ms 21964 KB Output is correct
17 Correct 64 ms 20684 KB Output is correct
18 Correct 23 ms 15188 KB Output is correct
19 Correct 81 ms 25292 KB Output is correct
20 Correct 91 ms 25676 KB Output is correct
21 Correct 66 ms 21836 KB Output is correct
22 Correct 62 ms 20684 KB Output is correct
23 Correct 91 ms 26828 KB Output is correct
24 Correct 6 ms 10836 KB Output is correct
25 Correct 79 ms 13520 KB Output is correct
26 Correct 121 ms 15316 KB Output is correct
27 Correct 2052 ms 32548 KB Output is correct
28 Correct 706 ms 25556 KB Output is correct
29 Correct 2253 ms 25804 KB Output is correct
30 Correct 1298 ms 22076 KB Output is correct
31 Correct 1295 ms 20844 KB Output is correct
32 Correct 133 ms 15308 KB Output is correct
33 Correct 705 ms 25432 KB Output is correct
34 Correct 2231 ms 25740 KB Output is correct
35 Correct 1394 ms 21964 KB Output is correct
36 Correct 1282 ms 20728 KB Output is correct
37 Correct 648 ms 26844 KB Output is correct
38 Correct 1802 ms 39872 KB Output is correct