10442 | 2024-04-02 17:03:32 | 111 | Labirintus | cpp17 | Wrong answer 0/100 | 388ms | 189116 KiB |
#include<bits/stdc++.h>
using namespace std;
// #define int long long
struct DSU{
vector<int>v;
vector<pair<int,int>>s;
DSU(){
}
DSU(int n):v(n,-1){
}
int find(int i){
return v[i]<0?i:find(v[i]);
}
void unite(int a,int b){
a=find(a);
b=find(b);
if(a==b){
s.emplace_back(-1,-1);
s.emplace_back(-1,-1);
return;
}
if(a>b){
swap(a,b);
}
s.emplace_back(a,v[a]);
s.emplace_back(b,v[b]);
v[a]+=v[b];
v[b]=a;
}
void undo(){
for(int i=0;i<2;i++){
auto[a,aa]=s.back();
s.pop_back();
if(a!=-1){
v[a]=aa;
}
}
}
};
int R,C;
DSU d;
int x(int r,int c){
return r*(C+1)+c;
}
void init_labyrinth(int R_,int C_,std::vector<std::vector<int>>L){
R=R_,C=C_;
d=DSU((R+1)*(C+1));
for(int i=0;i+1<C;i++){
d.unite(x(R,i),x(R,i+1));
}
for(int i=0;i+1<R;i++){
d.unite(x(i,C),x(i+1,C));
}
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(L[i][j]){
d.unite(x(i,j),x(i,j+1));
d.unite(x(i,j),x(i+1,j));
d.unite(x(i,j),x(i+1,j+1));
}
}
}
}
bool can_escape(int N,std::vector<int>U,std::vector<int>V){
for(int k=0;k<N;k++){
int i=U[k],j=V[k];
d.unite(x(i,j),x(i,j+1));
d.unite(x(i,j),x(i+1,j));
d.unite(x(i,j),x(i+1,j+1));
}
int ans=d.find(x(R,C-1))!=d.find(x(R-1,C));
for(int k=0;k<N;k++){
d.undo();
d.undo();
d.undo();
}
return ans;
}
#ifdef LOCAL
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int R,C,Q;
cin>>R>>C>>Q;
vector<vector<int>>L(R,vector<int>(C));
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
char c;
cin>>c;
L[i][j]=c-'0';
}
}
init_labyrinth(R,C,L);
while(Q--){
int N;
cin>>N;
vector<int>U(N),V(N);
for(int i=0;i<N;i++){
cin>>U[i]>>V[i];
}
cout<<can_escape(N,U,V)<<'\n';
}
return 0;
}
#endif
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Wrong answer | 182ms | 92356 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Wrong answer | 28ms | 7412 KiB | ||||
4 | Wrong answer | 8ms | 7836 KiB | ||||
5 | Wrong answer | 125ms | 8528 KiB | ||||
6 | Wrong answer | 125ms | 10696 KiB | ||||
7 | Wrong answer | 83ms | 15484 KiB | ||||
8 | Wrong answer | 85ms | 17412 KiB | ||||
subtask3 | 0/18 | ||||||
9 | Wrong answer | 186ms | 18912 KiB | ||||
10 | Wrong answer | 187ms | 21452 KiB | ||||
11 | Wrong answer | 388ms | 110952 KiB | ||||
12 | Wrong answer | 363ms | 115916 KiB | ||||
13 | Wrong answer | 368ms | 120548 KiB | ||||
14 | Wrong answer | 386ms | 125076 KiB | ||||
subtask4 | 0/28 | ||||||
15 | Accepted | 263ms | 129948 KiB | ||||
16 | Accepted | 275ms | 133736 KiB | ||||
17 | Accepted | 277ms | 136312 KiB | ||||
18 | Accepted | 167ms | 140760 KiB | ||||
19 | Wrong answer | 272ms | 142376 KiB | ||||
20 | Accepted | 143ms | 146880 KiB | ||||
21 | Accepted | 148ms | 147984 KiB | ||||
22 | Wrong answer | 270ms | 149116 KiB | ||||
23 | Wrong answer | 266ms | 153836 KiB | ||||
subtask5 | 0/39 | ||||||
24 | Wrong answer | 37ms | 68476 KiB | ||||
25 | Wrong answer | 18ms | 68540 KiB | ||||
26 | Wrong answer | 126ms | 72136 KiB | ||||
27 | Wrong answer | 126ms | 74476 KiB | ||||
28 | Wrong answer | 123ms | 77324 KiB | ||||
29 | Wrong answer | 123ms | 77428 KiB | ||||
30 | Wrong answer | 370ms | 166472 KiB | ||||
31 | Wrong answer | 340ms | 169884 KiB | ||||
32 | Wrong answer | 244ms | 173448 KiB | ||||
33 | Wrong answer | 351ms | 175060 KiB | ||||
34 | Wrong answer | 245ms | 178852 KiB | ||||
35 | Wrong answer | 234ms | 180744 KiB | ||||
36 | Wrong answer | 289ms | 182696 KiB | ||||
37 | Wrong answer | 287ms | 185476 KiB | ||||
38 | Accepted | 293ms | 187404 KiB | ||||
39 | Wrong answer | 289ms | 189116 KiB |