Submission #1218500

#TimeUsernameProblemLanguageResultExecution timeMemory
1218500trantrungkeinFurniture (JOI20_furniture)C++17
100 / 100
270 ms50420 KiB
#include <bits/stdc++.h>
 
#define fi           first 
#define si           second 
#define For(i,a,b)   for (int i = (a), _b =(b); i <= _b; ++i)
#define all(v)       v.begin(), v.end()
#define Unique(v)    v.erase(unique(all(v)), v.end())   
#define MASK(i)      (1LL << (i))
#define bit(i,n)     (((n)>>(i)) & 1)
#define Vii          vector<pair<int,int>>
#define setpr(x)     cout<<setprecision(x)<<fixed
#define Prior        priority_queue< pair<int,int> , Vii, greater<Pair> >
using namespace std;
 
const int Mod = 1E9 + 7;
const long long INF  = 4E18;
const int N = 2e3 + 1;
pair<int,int> par[N][N];
int n,m,vis[N][N],w[N][N],b[N*N],c[N*N],a[N][N],ans[N][N],q;
int dx[] {1,0}, dy[] {0,1};
struct node
{
    int u,v,w;
    bool operator < (const node &other) const{
        return w > other.w;
    }
};
bool ok(int i, int j)
{
    return (1 <= i && i <= n && 1 <= j && j <= m && !vis[i][j]);
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> m;
    For(i,1,n) For(j,1,m)
        {   cin >> a[i][j];
            if(a[i][j]) w[i][j] = Mod;
            par[i][j] = {-1,-1};
        }
    cin >> q;
    For(i,1,q)
    {
        cin >> b[i] >> c[i];
        w[b[i]][c[i]] = q-i+1;
    }
    priority_queue<node> qer;
    qer.push({1,1,0});
    while(!qer.empty())
    {
        node o = qer.top();qer.pop();
        For(k,0,1)
        {   
            int x = o.u + dx[k], y = o.v + dy[k];
            if(ok(x,y)) qer.push({x,y,w[x][y]}), par[x][y] = {o.u,o.v}, vis[x][y] = 1; 
        }
    }
    int x = n, y = m;
    while(x != -1)
    {   
        ans[x][y] = 1;
        tie(x,y) = par[x][y];
    }
    For(i,1,q)
        cout << !ans[b[i]][c[i]] <<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...