Submission #94948

# Submission time Handle Problem Language Result Execution time Memory
94948 2019-01-25T12:22:48 Z SuperJava Flood (IOI07_flood) C++17
43 / 100
48 ms 30684 KB
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (515)
#define MOD (1000000000l + 7l)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global
vector<pair<int,int>> p;
set<pair<int,int>> adj[N][N];

int water[N][N];
int tx[4] = {1,-1,0,0};
int ty[4] = {0,0,1,-1};

void dfs(int x,int y,int c){
	water[x][y] = c;
	for (int i = 0; i < 4; ++i){
		if(x+tx[i] > -1 && x+tx[i] < 501 && y+ty[i] > -1 && y+ty[i] < 501){
			if(water[x+tx[i]][y+ty[i]] > c){
				if(!adj[x][y].count({x+tx[i],y+ty[i]})){
					dfs(x+tx[i],y+ty[i],c);
				}
			}
		}
	}
}

int main(){
	rep(i,0,502){
		rep(j,0,502){
			water[i][j] = OO;
		}
	}
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	int n;
	cin >> n;
	rep(i,0,n){
		int x,y;
		cin >> x >> y;
		p.emplace_back(x,y);
	}
	int m;
	cin >> m;
	vector<pair<int,int>> s;
	rep(i,0,m){
		int q,w;
		cin >> q >> w;
		q--; w--;
		if(p[q] > p[w]) swap(q,w);
		s.emplace_back(q,w);
		if(p[q].first == p[w].first){
			for (int j = p[q].second; j < p[w].second; ++j){
				adj[p[q].first-1][j].insert({p[q].first,j});
				adj[p[q].first][j].insert({p[q].first-1,j});
			}
		}
		else{
			for (int j = p[q].first; j < p[w].first; ++j){
				adj[j][p[q].second-1].insert({j,p[q].second});
				adj[j][p[q].second].insert({j,p[q].second-1});
			}
		}
	}
	dfs(0,0,1);
	int c = 1;
	while(true){
		rep(i,1,501){
			rep(j,1,501){
				if(water[i][j] == OO){
					if(water[i+1][j] == c || water[i-1][j] == c || water[i][j+1] == c || water[i][j-1] == c){
						dfs(i,j,min({water[i-1][j],water[i+1][j],water[i][j-1],water[i][j+1]})+1);
					}
				}
			}
		}
		c++;
		int r = 0;
		rep(i,1,501){
			rep(j,1,501){
				if(water[i][j] == OO){
					r++;
					break;
				}
			}
			if(r) break;
		}
		if(!r) break;
	}
	int xc = 0;
	rep(i,0,m){
		if(p[s[i].first].first == p[s[i].second].first){
			if(water[p[s[i].first].first-1][p[s[i].first].second] == 
				water[p[s[i].first].first][p[s[i].first].second]){
				xc++;
			}
		}else{
			if(water[p[s[i].first].first][p[s[i].first].second-1] == 
				water[p[s[i].first].first][p[s[i].first].second]){
				xc++;
			}
		}
	}
	cout << xc << endl;
	rep(i,0,m){
		if(p[s[i].first].first == p[s[i].second].first){
			if(water[p[s[i].first].first-1][p[s[i].first].second] == 
				water[p[s[i].first].first][p[s[i].first].second]){
				cout << i+1 << endl;
			}
		}else{
			if(water[p[s[i].first].first][p[s[i].first].second-1] == 
				water[p[s[i].first].first][p[s[i].first].second]){
				cout << i+1 << endl;
			}
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 28536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 24696 KB Output is correct
2 Correct 30 ms 24568 KB Output is correct
3 Correct 30 ms 24568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 22264 KB Output is correct
2 Correct 37 ms 23160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 24312 KB Output is correct
2 Correct 38 ms 27768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 27612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 27512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 27640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 27512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 28764 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 30448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 46 ms 30556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 30576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 30684 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -