Submission #129830

# Submission time Handle Problem Language Result Execution time Memory
129830 2019-07-13T10:10:03 Z khulegub Flood (IOI07_flood) C++14
82 / 100
2000 ms 11772 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[100010][4];
bool path[100010];
int arr[4][4];
vector<pii> wll;
vector<int> uld;
vector<pair<pair<int, int> , int> > p;

int dfs(int u, int dir, bool f){
	if (path[u]) return u;
	path[u] = 1;
	for (int i = 0; i < 4; i++){
		int v = to[u][arr[dir][i]];
		if (f == 0 && i == 3) continue;
		if (v != 0){
			int tmp = dfs(v, arr[dir][i], 0);
			if (tmp != -1){
				to[u][arr[dir][i]] = 0;
				to[v][ (arr[dir][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;
	for (int i = 0; i < 4; i++){
		arr[i][0] = (i + 1) % 4;
		arr[i][1] = i;
		arr[i][2] = (i + 3) % 4;
		arr[i][3] = (i + 2) % 4;
	}
	p.resize(n + 1);
	p[0] = mp(mp(-1,-1),-1);
	for (int i = 1, tx, ty; i <= n; i++){
		cin >> tx >> ty;
		p[i] = 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.xx - p[a].xx.xx;
		int dy = p[b].xx.yy - p[a].xx.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(p.begin(), p.end());
	for (int i = 1; i <= n; i++){
		dfs(p[i].yy , 0, 1);
	}
	if( w - xac < 0){
		cout << 0;
		return 0;
	}
	cout << w - xac << '\n';
	for (int i = 1; i <= w; i++){
		if ( to[wll[i].xx][wll[i].yy] != 0 ) cout << i << '\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 4 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2095 ms 4936 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3576 KB Output is correct
2 Correct 112 ms 4904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4620 KB Output is correct
2 Correct 105 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 4880 KB Output is correct
2 Execution timed out 2041 ms 11772 KB Time limit exceeded