///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
//#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
vector<vector<int>>arr;
int n,m;
int q;
int dp[101][101];
int ans(int i,int j)
{
if(i>n||j>m)return 0;
if(i==n-1&&j==m-1)
return 1;
if(dp[i][j]!=-1)return dp[i][j];
int e=0;
if(i+1<n&&arr[i+1][j]!=1)e=ans(i+1,j);
if(j+1<m&&arr[i][j+1]!=1)e=max(e,ans(i,j+1));
return dp[i][j]=e;
}
void preprocess() {}
void solve()
{
cin>>n>>m;
arr.resize(n);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int x;
cin>>x;
arr[i].push_back(x);
}
}
int q;
cin>>q;
while(q--)
{
memset(dp,-1,sizeof dp);
int i,j;
cin>>i>>j;
i--,j--;
arr[i][j]=1;
int x=ans(0,0);
cout<<x<<endl;
if(x==0)arr[i][j]=0;
}
}
signed main()
{
// freopen("div7.in","r",stdin);
//freopen("div7.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
//bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
600 KB |
Output is correct |
2 |
Correct |
18 ms |
600 KB |
Output is correct |
3 |
Correct |
60 ms |
600 KB |
Output is correct |
4 |
Correct |
99 ms |
600 KB |
Output is correct |
5 |
Correct |
112 ms |
604 KB |
Output is correct |
6 |
Correct |
201 ms |
624 KB |
Output is correct |
7 |
Correct |
83 ms |
600 KB |
Output is correct |
8 |
Correct |
104 ms |
620 KB |
Output is correct |
9 |
Correct |
248 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
600 KB |
Output is correct |
2 |
Correct |
18 ms |
600 KB |
Output is correct |
3 |
Correct |
60 ms |
600 KB |
Output is correct |
4 |
Correct |
99 ms |
600 KB |
Output is correct |
5 |
Correct |
112 ms |
604 KB |
Output is correct |
6 |
Correct |
201 ms |
624 KB |
Output is correct |
7 |
Correct |
83 ms |
600 KB |
Output is correct |
8 |
Correct |
104 ms |
620 KB |
Output is correct |
9 |
Correct |
248 ms |
600 KB |
Output is correct |
10 |
Incorrect |
1070 ms |
1324 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |