# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
129831 |
2019-07-13T10:15:31 Z |
khulegub |
Flood (IOI07_flood) |
C++14 |
|
2000 ms |
11724 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];
int arr[4][4];
vector<pii> wll;
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);
}
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 |
248 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 |
3 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 |
3 ms |
380 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 |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2028 ms |
5064 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
3616 KB |
Output is correct |
2 |
Correct |
115 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
4600 KB |
Output is correct |
2 |
Correct |
112 ms |
4724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
4800 KB |
Output is correct |
2 |
Execution timed out |
2036 ms |
11724 KB |
Time limit exceeded |