//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;
vector<int> vzx,vzy;
rep(i,0,n){
int x,y;
cin >> x >> y;
p.emplace_back(x,y);
vzx.push_back(x);
vzy.push_back(y);
}
sort(vzx.begin(), vzx.end());
sort(vzy.begin(), vzy.end());
map<int,int> vxx,vxy;
rep(i,0,n){
vxx[vzx[i]] = i+1;
vxy[vzy[i]] = i+1;
}
rep(i,0,n){
p[i].first = vxx[p[i].first];
p[i].second = vxy[p[i].second];
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
29560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
29560 KB |
Output is correct |
2 |
Correct |
43 ms |
29560 KB |
Output is correct |
3 |
Correct |
39 ms |
29564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
27512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
28540 KB |
Output is correct |
2 |
Correct |
33 ms |
17272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
28664 KB |
Output is correct |
2 |
Correct |
40 ms |
27388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
29220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
20600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
24056 KB |
Output is correct |
2 |
Correct |
48 ms |
19000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
19704 KB |
Output is correct |
2 |
Correct |
35 ms |
22392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
30112 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
80 ms |
33792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
112 ms |
33792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
92 ms |
33136 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
89 ms |
32896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |