Submission #559758

# Submission time Handle Problem Language Result Execution time Memory
559758 2022-05-10T14:00:57 Z keta_tsimakuridze Tropical Garden (IOI11_garden) C++14
100 / 100
2705 ms 42220 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
const int Nn = 4e5 + 5;
int f[Nn], par[Nn][2], d[Nn][2], id[Nn][2], cur, to[Nn], in_cycle[Nn];
vector<int> V[Nn], from[Nn];
int calc(int t, int u) {
	int U = u;
	for(int i = 1; i <= cur; i++) f[i] = 0;
	
	while(!f[u]) {
		f[u] = 1;
		u = to[u];
	}
	int sz = 0;
	while(f[u] != 2) {
		f[u] = 2;
		u = to[u];
		++sz;
	}
	u = U;
	if(f[u] == 2) in_cycle[u] = 1;
	d[u][t] = 0; 
	queue<int> q; q.push(u);
	while(q.size()) {
		int u = q.front();
		q.pop();
		for(int i = 0; i < from[u].size(); i++) { 
			if(d[from[u][i]][t] <= d[u][t] + 1) continue;
			d[from[u][i]][t] = d[u][t] + 1;
			q.push(from[u][i]);
		}
	}
	return sz;
}
void count_routes(int N, int M, int p, int R[][2], int Q, int G[])
{
	++p;
	for(int i = 1; i <= N; i++) {
		
		id[i][0] = ++ cur;
		id[i][1] = ++ cur;
	}
	for(int i = 0; i < M; i++) {
		int u = R[i][0], v = R[i][1];
		++u, ++v;
		if(V[u].size() < 2) V[u].push_back(v);
		if(V[v].size() < 2) V[v].push_back(u);
	}
	
	for(int i = 1; i <= N; i++) {
		for(int j = 0; j < V[i].size(); j++) {
			to[id[i][j]] = id[V[i][j]][0];
			if(V[V[i][j]][0] == i && V[V[i][j]].size() > 1) {
				to[id[i][j]] = id[V[i][j]][1];
			}
			from[to[id[i][j]]].push_back(id[i][j]);
		}
	}
	for(int i = 1; i <= cur; i++) for(int t = 0; t < 2; t++) d[i][t] = 1e9 + 16;
	vector<int> cyc(2);
	cyc[0] = calc(0, id[p][0]); cyc[1] = calc(1, id[p][1]); 
	int x = 1e9;
	for(int i = 0; i < Q; i++) {
		int cnt = 0;
		for(int j = 1; j <= N; j++) {
			if(((!in_cycle[id[p][0]] && G[i] == d[id[j][0]][0]) 
			|| (in_cycle[id[p][0]] && G[i] >= d[id[j][0]][0] && (G[i] - d[id[j][0]][0]) % cyc[0] == 0)) && d[id[j][0]][0] <= x) ++cnt;
			else if(((!in_cycle[id[p][1]] && G[i] == d[id[j][0]][1]) 
			|| (in_cycle[id[p][1]] && G[i] >= d[id[j][0]][1] && (G[i] - d[id[j][0]][1]) % cyc[1] == 0)) && d[id[j][0]][1] <= x) ++cnt;
		}
		answer(cnt);
	}
}

Compilation message

garden.cpp: In function 'int calc(int, int)':
garden.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int i = 0; i < from[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int j = 0; j < V[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 11 ms 19156 KB Output is correct
3 Correct 10 ms 19284 KB Output is correct
4 Correct 9 ms 19064 KB Output is correct
5 Correct 9 ms 19148 KB Output is correct
6 Correct 10 ms 19284 KB Output is correct
7 Correct 10 ms 19072 KB Output is correct
8 Correct 12 ms 19248 KB Output is correct
9 Correct 12 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 11 ms 19156 KB Output is correct
3 Correct 10 ms 19284 KB Output is correct
4 Correct 9 ms 19064 KB Output is correct
5 Correct 9 ms 19148 KB Output is correct
6 Correct 10 ms 19284 KB Output is correct
7 Correct 10 ms 19072 KB Output is correct
8 Correct 12 ms 19248 KB Output is correct
9 Correct 12 ms 19284 KB Output is correct
10 Correct 11 ms 19084 KB Output is correct
11 Correct 23 ms 21832 KB Output is correct
12 Correct 38 ms 23496 KB Output is correct
13 Correct 52 ms 31112 KB Output is correct
14 Correct 119 ms 34156 KB Output is correct
15 Correct 170 ms 34376 KB Output is correct
16 Correct 106 ms 29856 KB Output is correct
17 Correct 86 ms 28492 KB Output is correct
18 Correct 32 ms 23992 KB Output is correct
19 Correct 128 ms 35716 KB Output is correct
20 Correct 163 ms 36172 KB Output is correct
21 Correct 96 ms 31460 KB Output is correct
22 Correct 87 ms 30028 KB Output is correct
23 Correct 130 ms 37424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 11 ms 19156 KB Output is correct
3 Correct 10 ms 19284 KB Output is correct
4 Correct 9 ms 19064 KB Output is correct
5 Correct 9 ms 19148 KB Output is correct
6 Correct 10 ms 19284 KB Output is correct
7 Correct 10 ms 19072 KB Output is correct
8 Correct 12 ms 19248 KB Output is correct
9 Correct 12 ms 19284 KB Output is correct
10 Correct 11 ms 19084 KB Output is correct
11 Correct 23 ms 21832 KB Output is correct
12 Correct 38 ms 23496 KB Output is correct
13 Correct 52 ms 31112 KB Output is correct
14 Correct 119 ms 34156 KB Output is correct
15 Correct 170 ms 34376 KB Output is correct
16 Correct 106 ms 29856 KB Output is correct
17 Correct 86 ms 28492 KB Output is correct
18 Correct 32 ms 23992 KB Output is correct
19 Correct 128 ms 35716 KB Output is correct
20 Correct 163 ms 36172 KB Output is correct
21 Correct 96 ms 31460 KB Output is correct
22 Correct 87 ms 30028 KB Output is correct
23 Correct 130 ms 37424 KB Output is correct
24 Correct 11 ms 19104 KB Output is correct
25 Correct 113 ms 22048 KB Output is correct
26 Correct 154 ms 24216 KB Output is correct
27 Correct 2313 ms 32124 KB Output is correct
28 Correct 1085 ms 36108 KB Output is correct
29 Correct 2705 ms 36240 KB Output is correct
30 Correct 1491 ms 31524 KB Output is correct
31 Correct 1508 ms 30160 KB Output is correct
32 Correct 117 ms 24268 KB Output is correct
33 Correct 1070 ms 35856 KB Output is correct
34 Correct 2624 ms 36228 KB Output is correct
35 Correct 1562 ms 31524 KB Output is correct
36 Correct 1496 ms 30076 KB Output is correct
37 Correct 834 ms 37468 KB Output is correct
38 Correct 2001 ms 42220 KB Output is correct