Submission #834077

# Submission time Handle Problem Language Result Execution time Memory
834077 2023-08-22T10:36:48 Z ttamx Tropical Garden (IOI11_garden) C++14
0 / 100
3 ms 5076 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>

using namespace std;

const int N=150005;
const int M=300005;
const int D=300000;

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

int trav(int t,int u,int s){
	if(dp[t][u][s]!=-2)return dp[t][u][s];
	dp[t][u][s]=-1;
	int v=adj[u][min(s,(int)adj[u].size()-1)];
	int res=trav(t,v,adj[v][0]==u);
	if(res!=-1)dp[t][u][s]=res+1;
	return dp[t][u][s];
}

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]=-2;
	for(int i=0;i<M;i++){
		int u=R[i][0],v=R[i][1];
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}
	dp[0][p][0]=dp[1][p][1]=0;
	for(int t=0;t<2;t++){
		for(int i=0;i<n;i++){
			int res=trav(t,i,0);
			if(res!=-1)cnt[t][res]++;
		}
		cyc[t]=trav(t,adj[p][t],adj[adj[p][0]][t]==p);
		if(cyc[t]!=-1){
			cyc[t]++;
			for(int i=cyc[t];i<=D;i++)cnt[t][i]+=cnt[t][i-cyc[t]];
		}
	}
	for(int i=0;i<Q;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]<0)continue;
				if(dp[t][u][0]>G[i])continue;
				int d=G[i]-dp[t][u][0];
				if(cyc[t]!=-1)d%=cyc[t];
				ok|=d==0;
			}
			if(ok)cerr << u << " ";
			ans+=ok;
		}
		cerr << "\n";
		answer(ans);
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -