답안 #14689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14689 2015-06-05T02:28:07 Z minsu 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
49 / 100
29 ms 8544 KB
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "garden.h"
#include "gardenlib.h"
#include <queue>
using namespace std;
const int MAXN=1e6;
int elast[MAXN], eprev[MAXN], eadj[MAXN], eind;
int bpath[MAXN][2], bpathn[MAXN];
int L[MAXN], C[MAXN];
void add_edge(int u, int v){
  eadj[eind]=v; eprev[eind]=elast[u]; elast[u]=eind++;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
  for(int i=0;i<M;i++){
    int u=R[i][0], v=R[i][1];
    if(bpathn[u]<2) bpath[u][bpathn[u]++]=v;
    if(bpathn[v]<2) bpath[v][bpathn[v]++]=u;
  }
  for(int i=0;i<N;i++) if(bpathn[i]==1) bpath[i][1]=bpath[i][0], bpathn[i]++;
  memset( elast, -1, sizeof elast );
  // Vertex 0 to 2*N-1
  for(int u=0;u<N;u++){
  	if(bpathn[u]==0) continue;
    int F=bpath[u][0], S=bpath[u][1];
    if(bpath[F][0]!=u) add_edge(F*2, u*2); else add_edge(F*2+1, u*2);
    if(bpath[S][0]!=u) add_edge(S*2, u*2+1); else add_edge(S*2+1, u*2+1);
  }
  queue<int> q; q.push(P*2); q.push(P*2+1);
  L[P*2]=L[P*2+1]=0; C[P*2]=0; C[P*2+1]=1;
  while(!q.empty()){
  	int here=q.front(); q.pop();
  	for(int i=elast[here];i!=-1;i=eprev[i]){
  		int there=eadj[i]; 
  		L[there]=L[here]+1; C[there]=C[here];
  		if(there/2==P) continue;
  		q.push(there);
  	}
  }
  int eaten = ( C[P*2]==1 ? 0 : 1);
  for(int i=0;i<Q;i++){
  	int ans=0;
  	for(int b=0;b<2*N;b+=2){
  		int g=G[i];
  		if(g==L[b]) { ans++; continue; }
  		if(C[b]==eaten){
  			g-=L[b]; g-=L[P*2+eaten];
  		}else{
  			g-=L[b];
  		}
  		if(g>=0 && g%L[P*2+(eaten^1)]==0) ans++;
  	}
  	answer(ans);
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4344 KB Output is correct
2 Correct 6 ms 4316 KB Output is correct
3 Correct 5 ms 4316 KB Output is correct
4 Correct 6 ms 4316 KB Output is correct
5 Correct 5 ms 4216 KB Output is correct
6 Correct 6 ms 4344 KB Output is correct
7 Correct 5 ms 4316 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 7 ms 4340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4344 KB Output is correct
2 Correct 6 ms 4316 KB Output is correct
3 Correct 5 ms 4316 KB Output is correct
4 Correct 6 ms 4316 KB Output is correct
5 Correct 5 ms 4216 KB Output is correct
6 Correct 6 ms 4344 KB Output is correct
7 Correct 5 ms 4316 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 7 ms 4340 KB Output is correct
10 Correct 5 ms 4216 KB Output is correct
11 Correct 11 ms 5240 KB Output is correct
12 Correct 20 ms 6164 KB Output is correct
13 Incorrect 29 ms 8544 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4344 KB Output is correct
2 Correct 6 ms 4316 KB Output is correct
3 Correct 5 ms 4316 KB Output is correct
4 Correct 6 ms 4316 KB Output is correct
5 Correct 5 ms 4216 KB Output is correct
6 Correct 6 ms 4344 KB Output is correct
7 Correct 5 ms 4316 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 7 ms 4340 KB Output is correct
10 Correct 5 ms 4216 KB Output is correct
11 Correct 11 ms 5240 KB Output is correct
12 Correct 20 ms 6164 KB Output is correct
13 Incorrect 29 ms 8544 KB Output isn't correct
14 Halted 0 ms 0 KB -