#include<bits/stdc++.h>
#define st first
#define nd second
#define eb emplace_back
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){cerr<<h;if(sizeof...(t))cerr<<", ";debug(t...);};
#define deb(x...) cerr<<#x<<" = ";debug(x);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=1e3+5, INF=1e9+5;
set<int> S[N];
int dp[N], dp2[N];
int main(){
//ios_base::sync_with_stdio(0);cin.tie(0);
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++){
S[i].insert(m+1);
if(i!=1)S[i].insert(0);
for(int j=1; j<=m; j++){
int x;
cin>>x;
if(x)S[i].insert(j);
}
}
dp[0]=1;
for(int i=1; i<=n; i++){
auto it=S[i].lower_bound(dp[i-1]-1);
dp[i]=*it;
}
int q;
cin>>q;
while(q--){
/*for(int i=1; i<=n; i++){
deb(dp[i], dp2[i]);
}*/
int x, y;
cin>>x>>y;
S[x].insert(y);
dp[0]=1;
for(int i=1; i<=n; i++){
auto it=S[i].lower_bound(dp[i-1]-1);
dp[i]=*it;
}
if(dp[n]){
cout<<1<<"\n";
}
else{
cout<<0<<"\n";
S[x].erase(y);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Incorrect |
11 ms |
480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Incorrect |
11 ms |
480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |