Submission #261652

# Submission time Handle Problem Language Result Execution time Memory
261652 2020-08-11T23:33:25 Z super_j6 Tropical Garden (IOI11_garden) C++14
100 / 100
4644 ms 30460 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
 
const int inf = 0x3f3f3f3f;
const int mxn = 300000;
int a[mxn][2], f[mxn][2];
int d[mxn], p[mxn], vis[mxn];
vector<int> g[mxn];
int ans[mxn];
 
void dfs(int c){
	vis[c] = 1;
	for(int i : g[c]){
		if(vis[i]) continue;
		d[i] = d[c] + 1;
		dfs(i);
	}
}

void answer(int x);
 
void count_routes(int n, int m, int k, int e[][2], int q, int qr[]){
	memset(a, inf, sizeof(a));
	memset(p, -1, sizeof(p));
	for(int i = 0; i < m; i++)
	for(int j = 0; j < 2; j++){
		int x = e[i][j];
		a[x][1] = min(a[x][1], i);
		sort(a[x], a[x] + 2);
	}
	
	for(int i = 0; i < n; i++){
		if(a[i][0] == inf){
			p[i] = i;
			g[i].push_back(i);
		}
	} 
	for(int i = 0; i < m; i++)
	for(int j = 0; j < 2; j++){
		int x = e[i][j], y = e[i][!j];
		for(int l = 0; l < 2; l++){
			if(a[x][l] == i){
				int u = (a[y][0] == i && a[y][1] != inf) * n + y, v = l * n + x;
				p[v] = u;
				g[u].push_back(v);
			} 
		}
	}
	
	for(int t = 0; t < 2; t++){
		memset(d, inf, sizeof(d));
		memset(vis, 0, sizeof(vis));
		
		int x = t * n + k, y, l;
		for(y = x; ~y && !vis[y]; y = p[y]) vis[y] = 1;
		for(int i = p[x]; i != y; i = p[i]) vis[i] = 0;
		
		d[x] = 0;
		dfs(x);
		if(x == y) l = d[p[x]] + 1;
		for(int i = 0; i < n; i++)
		for(int j = 0; j < q; j++){
			if(x != y) ans[j] += d[i] == qr[j];
			else ans[j] += d[i] <= qr[j] && (d[i] % l) == (qr[j] % l);
		}
	}
	
	for(int i = 0; i < q; i++) answer(ans[i]);
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:73:57: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
    else ans[j] += d[i] <= qr[j] && (d[i] % l) == (qr[j] % l);
                                                  ~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 13312 KB Output is correct
2 Correct 9 ms 13312 KB Output is correct
3 Correct 10 ms 13312 KB Output is correct
4 Correct 9 ms 13312 KB Output is correct
5 Correct 9 ms 13312 KB Output is correct
6 Correct 10 ms 13440 KB Output is correct
7 Correct 9 ms 13312 KB Output is correct
8 Correct 9 ms 13312 KB Output is correct
9 Correct 11 ms 13440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 13312 KB Output is correct
2 Correct 9 ms 13312 KB Output is correct
3 Correct 10 ms 13312 KB Output is correct
4 Correct 9 ms 13312 KB Output is correct
5 Correct 9 ms 13312 KB Output is correct
6 Correct 10 ms 13440 KB Output is correct
7 Correct 9 ms 13312 KB Output is correct
8 Correct 9 ms 13312 KB Output is correct
9 Correct 11 ms 13440 KB Output is correct
10 Correct 9 ms 13312 KB Output is correct
11 Correct 18 ms 14592 KB Output is correct
12 Correct 41 ms 15608 KB Output is correct
13 Correct 56 ms 25600 KB Output is correct
14 Correct 88 ms 20472 KB Output is correct
15 Correct 117 ms 20860 KB Output is correct
16 Correct 95 ms 19320 KB Output is correct
17 Correct 96 ms 18680 KB Output is correct
18 Correct 31 ms 15608 KB Output is correct
19 Correct 91 ms 20472 KB Output is correct
20 Correct 121 ms 20728 KB Output is correct
21 Correct 95 ms 19192 KB Output is correct
22 Correct 99 ms 18912 KB Output is correct
23 Correct 84 ms 20984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 13312 KB Output is correct
2 Correct 9 ms 13312 KB Output is correct
3 Correct 10 ms 13312 KB Output is correct
4 Correct 9 ms 13312 KB Output is correct
5 Correct 9 ms 13312 KB Output is correct
6 Correct 10 ms 13440 KB Output is correct
7 Correct 9 ms 13312 KB Output is correct
8 Correct 9 ms 13312 KB Output is correct
9 Correct 11 ms 13440 KB Output is correct
10 Correct 9 ms 13312 KB Output is correct
11 Correct 18 ms 14592 KB Output is correct
12 Correct 41 ms 15608 KB Output is correct
13 Correct 56 ms 25600 KB Output is correct
14 Correct 88 ms 20472 KB Output is correct
15 Correct 117 ms 20860 KB Output is correct
16 Correct 95 ms 19320 KB Output is correct
17 Correct 96 ms 18680 KB Output is correct
18 Correct 31 ms 15608 KB Output is correct
19 Correct 91 ms 20472 KB Output is correct
20 Correct 121 ms 20728 KB Output is correct
21 Correct 95 ms 19192 KB Output is correct
22 Correct 99 ms 18912 KB Output is correct
23 Correct 84 ms 20984 KB Output is correct
24 Correct 13 ms 13312 KB Output is correct
25 Correct 197 ms 14720 KB Output is correct
26 Correct 287 ms 15612 KB Output is correct
27 Correct 4343 ms 25672 KB Output is correct
28 Correct 1581 ms 20556 KB Output is correct
29 Correct 4644 ms 20792 KB Output is correct
30 Correct 2887 ms 19320 KB Output is correct
31 Correct 2555 ms 18808 KB Output is correct
32 Correct 204 ms 15616 KB Output is correct
33 Correct 1572 ms 20472 KB Output is correct
34 Correct 4568 ms 20776 KB Output is correct
35 Correct 2866 ms 19316 KB Output is correct
36 Correct 2528 ms 18936 KB Output is correct
37 Correct 1402 ms 21144 KB Output is correct
38 Correct 4321 ms 30460 KB Output is correct