Submission #488630

#TimeUsernameProblemLanguageResultExecution timeMemory
488630cfalasFurniture (JOI20_furniture)C++14
5 / 100
5057 ms1112 KiB
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) int t, n, m; vector<vi> a, b, c; void calc(){ b[0][0] = 1; FORi(i,1,n) b[i][0] = min(b[i-1][0], (int)(a[i][0]==0)); FORi(i,1,m) b[0][i] = min(b[0][i-1], (int)(a[0][i]==0)); c[n-1][m-1] = 1; for(int i=n-2;i>=0;i--) c[i][m-1] = min(c[i+1][m-1], (int)(a[i][m-1]==0)); for(int i=m-2;i>=0;i--) c[n-1][i] = min(c[n-1][i+1], (int)(a[n-1][i]==0)); FORi(i,1,n){ FORi(j,1,m){ if(a[i][j]) b[i][j] = 0; else b[i][j] = b[i-1][j] + b[i][j-1]; } } for(int i=n-2;i>=0;i--){ for(int j=m-2;j>=0;j--){ if(a[i][j]) c[i][j] = 0; else c[i][j] = c[i+1][j] + c[i][j+1]; } } /** FOR(i,n){ FOR(j,m) cout<<c[i][j]<<" "; cout<<endl; }*/ //assert(b[n-1][m-1]!=0); } int main(){ cin>>n>>m; b.assign(n, vi(m)); c.assign(n, vi(m)); a.assign(n, vi(m)); FOR(i,n){ FOR(j,m) cin>>a[i][j]; } int q; cin>>q; calc(); /* FOR(i,n){ FOR(j,m) cout<<b[i][j]<<" "; cout<<endl; }*/ while(q--){ int x,y; cin>>x>>y; //cout<<b[n-1][m-1]<<" "<<b[x-1][y-1]<<" "<<c[x-1][y-1]<<endl; if(b[n-1][m-1]!=c[x-1][y-1]*b[x-1][y-1]){ cout<<1<<endl, a[x-1][y-1] = 1; calc(); } else cout<<0<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...