Submission #129819

# Submission time Handle Problem Language Result Execution time Memory
129819 2019-07-13T09:54:52 Z khulegub Flood (IOI07_flood) C++14
82 / 100
2000 ms 15716 KB
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long i64;
int xac = 0;
int n;
int w;
// bool dbg = 0;
int to[100005][4];
bool path[100005];
vector<pii> p;
vector<pii> wll;


int dfs(int u, int dir, bool f){
	if (path[u]) return u;
	path[u] = 1;
	int arr[4];
	arr[0] = (dir + 1) % 4;
	arr[1] = dir;
	arr[2] = (dir + 3) % 4;
	arr[3] = (dir + 2) % 4;
	for (int i = 0; i < 4; i++){
		int v = to[u][arr[i]];
		if (f == 0 && i == 3) continue;
		if (v != 0){
			int tmp = dfs(v, arr[i], 0);
			if (tmp != -1){
				to[u][arr[i]] = 0;
				to[v][ (arr[i] + 2) % 4 ] = 0;
				xac++;
				if (tmp != u){
					path[u] = 0;
					return tmp;
				}
			}
		}
	}
	path[u] = 0;
	return -1;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("in.txt", "r", stdin);
	cin >> n;
	vector<pair<pair<int, int> , int> > p2;
	p.resize(n + 1);
	p2.resize(n);
	for (int i = 1, tx, ty; i <= n; i++){
		cin >> tx >> ty;
		p[i] = mp(tx, ty);
		p2[i - 1] = mp(mp(tx,ty), i);
	}
	cin >> w;
	wll.resize(w + 1);

	for (int i = 1, a, b; i <= w; i++){
		cin >> a >> b;
		int dx = p[b].xx - p[a].xx;
		int dy = p[b].yy - p[a].yy;
		int dir;
		if (dx != 0){ // horizontal
			if (dx > 0) dir = 1;
			else dir = 3;
		}
		else{ //vert
			if (dy > 0) dir = 0;
			else dir = 2;
		}
		to[a][dir] = b;
		to[b][(dir + 2) % 4] = a;
		wll[i] = mp(a, dir);
	}
	sort(p2.begin(), p2.end());
	for (int i = 0; i < n; i++){
		dfs(p2[i].yy , 0, 1);
	}
	cout << w - xac << '\n';
	for (int i = 1; i <= w; i++){
		if ( to[wll[i].xx][wll[i].yy] != 0 ) cout << i << '\n';
		// if ( to[wll[i].xx][wll[i].yy] != 0 ) cout << wll[i].xx << ' ' << to[wll[i].xx][wll[i].yy] << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2024 ms 6348 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 52 ms 4344 KB Output is correct
2 Correct 111 ms 5808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 5496 KB Output is correct
2 Correct 107 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 5752 KB Output is correct
2 Execution timed out 2044 ms 15716 KB Time limit exceeded