Submission #147229

# Submission time Handle Problem Language Result Execution time Memory
147229 2019-08-28T12:35:04 Z jhwest2 Tropical Garden (IOI11_garden) C++14
69 / 100
5000 ms 28880 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef pair<int, int> pii;

const int MAX = 150101;
vector<int> arr[MAX];
vector<int> edge[MAX*2];
pii dist[2*MAX];
bool chk[2*MAX];
queue<pii> q;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	 for (int i=0; i<M; i++) {
	 	if (arr[R[i][0]].size() != 2)
	 		arr[R[i][0]].push_back(R[i][1]);
	 	if (arr[R[i][1]].size() != 2)
	 		arr[R[i][1]].push_back(R[i][0]);
	 }

	 for (int i=0; i<=N; i++) {
	 	while (arr[i].size() != 2)
	 		arr[i].push_back(N);
	 }

	 for (int i=0; i<N; i++) {
	 	if (arr[i][1] == N) {
	 		if (arr[arr[i][0]][0] == i) {
	 			edge[N+arr[i][0]].push_back(i);
	 			edge[N+arr[i][0]].push_back(N+i);
	 		}
	 		else {
	 			edge[arr[i][0]].push_back(i);
	 			edge[arr[i][0]].push_back(N+i);
	 		}
	 		continue;
	 	}
	 	if (arr[arr[i][0]][0] == i)
	 		edge[N+arr[i][0]].push_back(i);
	 	else
	 		edge[arr[i][0]].push_back(i);

	 	if (arr[arr[i][1]][0] == i)
	 		edge[N+arr[i][1]].push_back(N+i);
	 	else
	 		edge[arr[i][1]].push_back(N+i);
	 }

	 memset(dist, -1, sizeof dist);

	 q.push(pii(P, 0));
	 while (!q.empty()) {
	 	pii tmp = q.front();
	 	q.pop();

	 	if (chk[tmp.va]) continue;
	 	if (tmp.vb != 0) {
	 		chk[tmp.va] = true;
	 		dist[tmp.va].va = tmp.vb;
	 	}

	 	for (int i=0; i<edge[tmp.va].size(); i++)
	 		q.push(pii(edge[tmp.va][i], tmp.vb+1));
	 }

	 memset(chk, false, sizeof chk);
	 q.push(pii(N+P, 0));
	 while (!q.empty()) {
	 	pii tmp = q.front();
	 	q.pop();

	 	if (chk[tmp.va]) continue;
	 	if (tmp.vb != 0) {
	 		chk[tmp.va] = true;
	 		dist[tmp.va].vb = tmp.vb;
	 	}

	 	for (int i=0; i<edge[tmp.va].size(); i++)
	 		q.push(pii(edge[tmp.va][i], tmp.vb+1));
	 }

	 for (int i=0; i<Q; i++) {
	 	int mod = dist[P].va;
	 	int ans = 0;
	 	for (int j=0; j<N; j++) {
	 		if (dist[j].va == -1) continue;
	 		if ((G[i] > dist[j].va && mod != -1 && G[i]%mod == dist[j].va%mod) || G[i] == dist[j].va) ++ans;
	 	}

	 	mod = dist[N+P].vb;
	 	for (int j=0; j<N; j++) {
	 		if (dist[j].vb == -1) continue;
	 		if ((G[i] > dist[j].vb && mod != -1 && G[i]%mod == dist[j].vb%mod) || G[i] == dist[j].vb) ++ans;
	 	}

	 	answer(ans);
	 }
	 return;
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:65:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i=0; i<edge[tmp.va].size(); i++)
                  ~^~~~~~~~~~~~~~~~~~~~
garden.cpp:81:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i=0; i<edge[tmp.va].size(); i++)
                  ~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 13560 KB Output is correct
2 Correct 14 ms 13688 KB Output is correct
3 Correct 14 ms 13688 KB Output is correct
4 Correct 14 ms 13560 KB Output is correct
5 Correct 14 ms 13532 KB Output is correct
6 Correct 14 ms 13688 KB Output is correct
7 Correct 14 ms 13532 KB Output is correct
8 Correct 14 ms 13560 KB Output is correct
9 Correct 16 ms 13692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 13560 KB Output is correct
2 Correct 14 ms 13688 KB Output is correct
3 Correct 14 ms 13688 KB Output is correct
4 Correct 14 ms 13560 KB Output is correct
5 Correct 14 ms 13532 KB Output is correct
6 Correct 14 ms 13688 KB Output is correct
7 Correct 14 ms 13532 KB Output is correct
8 Correct 14 ms 13560 KB Output is correct
9 Correct 16 ms 13692 KB Output is correct
10 Correct 14 ms 13548 KB Output is correct
11 Correct 25 ms 15352 KB Output is correct
12 Correct 43 ms 16516 KB Output is correct
13 Correct 61 ms 22264 KB Output is correct
14 Correct 149 ms 23416 KB Output is correct
15 Correct 164 ms 23780 KB Output is correct
16 Correct 123 ms 20856 KB Output is correct
17 Correct 103 ms 20088 KB Output is correct
18 Correct 45 ms 16508 KB Output is correct
19 Correct 144 ms 23416 KB Output is correct
20 Correct 175 ms 23740 KB Output is correct
21 Correct 126 ms 20856 KB Output is correct
22 Correct 113 ms 20056 KB Output is correct
23 Correct 149 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 13560 KB Output is correct
2 Correct 14 ms 13688 KB Output is correct
3 Correct 14 ms 13688 KB Output is correct
4 Correct 14 ms 13560 KB Output is correct
5 Correct 14 ms 13532 KB Output is correct
6 Correct 14 ms 13688 KB Output is correct
7 Correct 14 ms 13532 KB Output is correct
8 Correct 14 ms 13560 KB Output is correct
9 Correct 16 ms 13692 KB Output is correct
10 Correct 14 ms 13548 KB Output is correct
11 Correct 25 ms 15352 KB Output is correct
12 Correct 43 ms 16516 KB Output is correct
13 Correct 61 ms 22264 KB Output is correct
14 Correct 149 ms 23416 KB Output is correct
15 Correct 164 ms 23780 KB Output is correct
16 Correct 123 ms 20856 KB Output is correct
17 Correct 103 ms 20088 KB Output is correct
18 Correct 45 ms 16508 KB Output is correct
19 Correct 144 ms 23416 KB Output is correct
20 Correct 175 ms 23740 KB Output is correct
21 Correct 126 ms 20856 KB Output is correct
22 Correct 113 ms 20056 KB Output is correct
23 Correct 149 ms 24312 KB Output is correct
24 Correct 15 ms 13588 KB Output is correct
25 Correct 119 ms 15440 KB Output is correct
26 Correct 155 ms 16504 KB Output is correct
27 Correct 2775 ms 22332 KB Output is correct
28 Correct 1525 ms 23668 KB Output is correct
29 Correct 3093 ms 23824 KB Output is correct
30 Correct 1695 ms 20912 KB Output is correct
31 Correct 1649 ms 20088 KB Output is correct
32 Correct 170 ms 16632 KB Output is correct
33 Correct 1507 ms 23524 KB Output is correct
34 Correct 2875 ms 23820 KB Output is correct
35 Correct 1687 ms 20912 KB Output is correct
36 Correct 2241 ms 20148 KB Output is correct
37 Correct 1065 ms 24456 KB Output is correct
38 Execution timed out 5048 ms 28880 KB Time limit exceeded