# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
887106 |
2023-12-13T19:18:30 Z |
Macker |
Flood (IOI07_flood) |
C++17 |
|
224 ms |
27764 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
vector<array<int, 4>> adj;
vector<array<int, 4>> adji;
vector<int> res;
vector<int> vis;
int strt = -1;
bool dfs(int a, int dir, int r){
for (int i = -1; i < 3; i++) {
int j = (i + dir + 4) % 4;
int b = adj[a][j];
if(b == strt){
if(vis[adji[a][j]] == r) res.push_back(adji[a][j]);
adj[a][j] = -1;
adj[b][(j + 2) % 4] = -1;
return 1;
}
if(b != -1){
if(vis[adji[a][j]] == r){
res.push_back(adji[a][j]);
adj[a][j] = -1;
adj[b][(j + 2) % 4] = -1;
}
vis[adji[a][j]] = r;
vis[adji[b][(j + 2) % 4]] = r;
if(dfs(b, j, r)){
adj[a][j] = -1;
adj[b][(j + 2) % 4] = -1;
return 1;
}
}
}
return 0;
}
int main()
{
int n; cin >> n;
vector<array<int, 3>> pos(n);
vector<int> pord(n);
adj.resize(n, {-1, -1, -1, -1}); //up, left, down, right
adji.resize(n, {-1, -1, -1, -1}); //up, left, down, right
for (int i = 0; i < n; i++){
cin >> pos[i][0] >> pos[i][1];
pos[i][2] = i;
}
int w; cin >> w;
vis.resize(w, -1);
for (int i = 1; i <= w; i++) {
int a, b; cin >> a >> b; a--; b--;
if(pos[a][1] == pos[b][1]){
if(pos[a][0] > pos[b][0]){
adj[a][0] = b;
adj[b][2] = a;
adji[a][0] = i;
adji[b][2] = i;
}
else{
adj[a][2] = b;
adj[b][0] = a;
adji[a][2] = i;
adji[b][0] = i;
}
}
else{
if(pos[a][1] < pos[b][1]){
adj[a][3] = b;
adj[b][1] = a;
adji[a][3] = i;
adji[b][1] = i;
}
else{
adj[a][1] = b;
adj[b][3] = a;
adji[a][1] = i;
adji[b][3] = i;
}
}
}
sort(all(pos));
for (auto p : pos) {
if(adj[p[2]] == array<int, 4>({-1, -1, -1, -1})) continue;
for (int i = 0; i < 4; i++) {
if(adj[p[2]][i] != -1){
strt = p[2];
dfs(p[2], i, p[2]);
}
}
}
cout << res.size() << endl;
for (auto &&i : res)
cout << i << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
10836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
7196 KB |
Output is correct |
2 |
Correct |
192 ms |
9952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
9660 KB |
Output is correct |
2 |
Correct |
186 ms |
9464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
9476 KB |
Output is correct |
2 |
Correct |
224 ms |
27764 KB |
Output is correct |