➤ Problem Link : 1293C. NEKO's Maze Game
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; bool arr[3][100000+2]; int n; int total; bool func(int r,int c) { if(r<1 || r>2 || c<1 || c>n) return 0; if(arr[r][c]) { total++; return 1; } else return 0; } int main() { int q; cin>>n>>q; total = 0; memset(arr,0,sizeof(arr)); while(q--) { int r,c; bool ans; cin>>r>>c; arr[r][c]=arr[r][c]^1; if(arr[r][c]) { bool a = func(r+1,c); bool b=func(r-1,c); bool p = func(r+1,c+1); bool d = func(r+1,c-1); bool e= func(r-1,c+1); bool f =func(r-1,c-1); // cout<<r<<c<<" "<<d; if(a || b || p || d || e || f) ans=0; else { if(total==0) ans=1; else ans=0; } } else { if(r==1) { if(arr[r+1][c]) total--; if(arr[r+1][c-1]) total--; if(arr[r+1][c+1]) total--; } else { if(arr[r-1][c]) total--; if(arr[r-1][c-1]) total--; if(arr[r-1][c+1]) total--; } if(total==0) ans=1; else ans=0; } if(ans) cout<<"Yes\n"; else cout<<"NO\n"; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!