5556 | 2023-07-25 14:31:48 | marcipan5000 | Labirintus | cpp17 | Wrong answer 0/100 | 2.084s | 523884 KiB |
#include "labirintus.h"
#include <bits/stdc++.h>
using namespace std;
int r,c;
vector<vector<int> > h;
vector<vector<int> > w;
int tim=1;
bool prop[1000001];
vector<int> t[1000001];
vector<int> d;
void fill(int x,int y) {
if ((!((x>=0) && (x<r) && (y>=0) && (y<c))) || (h[x][y]!=0)) {
return;
}
h[x][y]=tim;
fill(x+1,y);
fill(x-1,y);
fill(x,y+1);
fill(x,y-1);
}
void init_labyrinth(int R, int C, std::vector<std::vector<int>> L) {
h=L; w=L;
r=R; c=C;
for (int i=0;i<r;i++) {
for (int j=0;j<c;j++) {
h[i][j]=0;
}
}
for (int i=0;i<r;i++) {
for (int j=0;j<c;j++) {
if ((L[i][j]==1) && (h[i][j]==0)) {
fill(i,j);
tim++;
}
if (L[i][j]==0) {
h[i][j]=tim;
tim++;
}
}
}
for (int i=1;i<c;i++) {
prop[h[0][i]]=1;
}
for (int i=0;i<r;i++) {
prop[h[i][c-1]]=1;
}
return;
}
int db=1;
int volt[1000001];
bool ans=0;
void dfs(int p) {
volt[p]=db;
for (int i:t[p]) {
if (volt[i]!=db) {
dfs(volt[i]);
}
}
ans=ans||prop[p];
}
bool can_escape(int N, std::vector<int> U, std::vector<int> V) {
ans=0;
for (int i=0;i<N;i++) {
if ((U[i] < r-1) && (h[U[i]][V[i]]!=h[U[i]+1][V[i]]) && (w[U[i]+1][V[i]]==1)) {
t[h[U[i]][V[i]]].push_back(h[U[i]+1][V[i]]);
t[h[U[i]+1][V[i]]].push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]+1][V[i]]);
}
if ((V[i] < c-1) && (h[U[i]][V[i]]!=h[U[i]][V[i]+1]) && (w[U[i]][V[i]+1]==1)) {
t[h[U[i]][V[i]]].push_back(h[U[i]][V[i]+1]);
t[h[U[i]][V[i]+1]].push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]][V[i]+1]);
}
if ((U[i] > 0) && (h[U[i]][V[i]]!=h[U[i]-1][V[i]]) && (w[U[i]-1][V[i]]==1)) {
t[h[U[i]][V[i]]].push_back(h[U[i]-1][V[i]]);
t[h[U[i]-1][V[i]]].push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]-1][V[i]]);
}
if ((V[i] > 0) && (h[U[i]][V[i]]!=h[U[i]][V[i]-1]) && (w[U[i]][V[i]-1]==1)) {
t[h[U[i]][V[i]]].push_back(h[U[i]][V[i]-1]);
t[h[U[i]][V[i]-1]].push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]][V[i]]);
d.push_back(h[U[i]][V[i]-1]);
}
w[U[i]][V[i]]=1;
}
for (int i=1;i<r;i++) {
if (volt[h[i][0]]!=db) {
dfs(h[i][0]);
}
}
for (int i=0;i<c;i++) {
if (volt[h[r-1][i]]!=db) {
dfs(h[r-1][i]);
}
}
for (int i=0;i<N;i++) {
w[U[i]][V[i]]=0;
}
for (int i:d) {
t[i].clear();
}
db++;
return(ans);
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 25ms | 48684 KiB | ||||
2 | Time limit exceeded | 2.065s | 90916 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Time limit exceeded | 2.079s | 170872 KiB | ||||
4 | Wrong answer | 30ms | 55900 KiB | ||||
5 | Wrong answer | 214ms | 62592 KiB | ||||
6 | Wrong answer | 444ms | 64988 KiB | ||||
7 | Wrong answer | 87ms | 63888 KiB | ||||
8 | Wrong answer | 89ms | 66100 KiB | ||||
subtask3 | 0/18 | ||||||
9 | Runtime error | 293ms | 523884 KiB | ||||
10 | Runtime error | 239ms | 523620 KiB | ||||
11 | Time limit exceeded | 2.075s | 92136 KiB | ||||
12 | Time limit exceeded | 2.078s | 95604 KiB | ||||
13 | Time limit exceeded | 2.072s | 95976 KiB | ||||
14 | Time limit exceeded | 2.084s | 96892 KiB | ||||
subtask4 | 0/28 | ||||||
15 | Wrong answer | 337ms | 190476 KiB | ||||
16 | Wrong answer | 337ms | 196100 KiB | ||||
17 | Wrong answer | 340ms | 201236 KiB | ||||
18 | Wrong answer | 224ms | 202648 KiB | ||||
19 | Time limit exceeded | 2.063s | 126120 KiB | ||||
20 | Wrong answer | 181ms | 209044 KiB | ||||
21 | Wrong answer | 180ms | 210312 KiB | ||||
22 | Time limit exceeded | 2.079s | 133540 KiB | ||||
23 | Time limit exceeded | 2.082s | 138308 KiB | ||||
subtask5 | 0/39 | ||||||
24 | Wrong answer | 1.756s | 93388 KiB | ||||
25 | Wrong answer | 412ms | 92288 KiB | ||||
26 | Wrong answer | 208ms | 102744 KiB | ||||
27 | Wrong answer | 444ms | 105024 KiB | ||||
28 | Wrong answer | 289ms | 108004 KiB | ||||
29 | Wrong answer | 439ms | 110768 KiB | ||||
30 | Time limit exceeded | 2.066s | 145108 KiB | ||||
31 | Time limit exceeded | 2.048s | 149056 KiB | ||||
32 | Time limit exceeded | 2.072s | 149692 KiB | ||||
33 | Time limit exceeded | 2.072s | 152424 KiB | ||||
34 | Time limit exceeded | 2.072s | 152528 KiB | ||||
35 | Time limit exceeded | 2.059s | 154004 KiB | ||||
36 | Wrong answer | 321ms | 247600 KiB | ||||
37 | Wrong answer | 323ms | 252580 KiB | ||||
38 | Wrong answer | 310ms | 257304 KiB | ||||
39 | Wrong answer | 338ms | 261460 KiB |