답안 #62880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62880 2018-07-30T15:42:45 Z reality 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
49 / 100
5000 ms 888 KB
#include "garden.h"
#include "gardenlib.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}

const int NN = 5e5 + 5;

int f[NN];

int deg[NN];

int Deg[NN];

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	vector < pii > e;
	int n = N;
	for (int i = 0;i < n + n;++i)
		f[i] = -1;
	for (int i = 0;i < M;++i) {
		int u = R[i][0];
		int v = R[i][1];
		++Deg[u];
		++Deg[v];
		smin(Deg[u],2);
		smin(Deg[v],2);
	}
	for (int i = 0;i < M;++i) {
		int u = R[i][0];
		int v = R[i][1];
		++deg[u];
		++deg[v];
		for (int cs = 0;cs < 2;++cs) {
			if (deg[u] == 1) {
				if (deg[v] >= Deg[v])
					f[u * 2] = v * 2;
				else
					f[u * 2] = v * 2 + 1;
			}
			else
			if (deg[u] == 2) {
				if (deg[v] >= Deg[v])
					f[u * 2 + 1] = v * 2;
				else
					f[u * 2 + 1] = v * 2 + 1;
			}
			swap(u,v);
		}
	}
	//for (int i = 0;i < n + n;++i)
	//	cerr << i << ' ' << f[i] << '\n';
	auto go = [&](int cnt,int cur) {
		while (cnt > 0 && cur >= 0) {
			--cnt;
			cur = f[cur];
		}
		return (cnt == 0) && (cur / 2) == P;
	};
	for (int i = 0;i < Q;++i) {
		int ans = 0;
		for (int j = 0;j < n + n;j += 2) {
			ans += go(G[i],j);
		}
		answer(ans);
	}
}


# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 476 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Execution timed out 5028 ms 888 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 476 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Execution timed out 5028 ms 888 KB Time limit exceeded
12 Halted 0 ms 0 KB -