General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
79994169 Practice:
tilakparth
1349C - 25 GNU C++17 Wrong answer on test 6 61 ms 21068 KB 2020-05-13 18:11:05 2020-05-13 18:11:05
 
 
→ Source
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long int 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=0;i<(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


int n,m,t;
string s[1000];
int arr[1000][1000];
int permutations[1000][1000];

void set_permutations(int i,int j){
    if(permutations[i][j]!=inf)return;
    int flag=0;
    int temp = inf;
    if(i>0)temp=min(temp,permutations[i-1][j]);
    if(j>0)temp=min(temp,permutations[i][j-1]);
    if(i<(n-1))temp=min(temp,permutations[i+1][j]);
    if(j<(m-1))temp=min(temp,permutations[i][j+1]);
    if(temp==inf)return;
    permutations[i][j]=temp+1;
    // cout<<temp<<endl;
    if(i>0)set_permutations(i-1,j);
    if(j>0)set_permutations(i,j-1);
    if(i<(n-1))set_permutations(i+1,j);
    if(j<(m-1))set_permutations(i,j+1);
}

int32_t main()
{
    c_p_c();
     
    cin>>n>>m>>t;
    from(i,n)cin>>s[i];
    from(i,n){
        from(j,m){
            if(s[i][j]=='0')arr[i][j]=0;
            else arr[i][j]=1;
        }
    }
    from(i,n){
        from(j,m){
            int flag=inf;
            if((i>0)&&(arr[i][j]==arr[i-1][j]))flag=1;
            if((j>0)&&(arr[i][j]==arr[i][j-1]))flag=1;
            if((i<(n-1))&&(arr[i][j]==arr[i+1][j]))flag=1;
            if((j<(m-1))&&(arr[i][j]==arr[i][j+1]))flag=1;
            permutations[i][j]=flag;
        }
    }
    
    // from(i,n){
    //     from(j,m)cout<<permutations[i][j]<<" ";
    //     cout<<endl;
    // }
    // cout<<endl<<endl;
    
    from(i,n){
        from(j,m)set_permutations(i,j);
    }
    // from(i,n){
    //     from(j,m)cout<<permutations[i][j]<<" ";
    //     cout<<endl;
    // }
    
    while(t--){
        int x,y,p; cin>>x>>y>>p;
        x--;y--;
        if(permutations[x][y]==inf){
            cout<<arr[x][y]<<"\n";
        }
        else{
            if(permutations[x][y]>p)cout<<arr[x][y]<<"\n";
            else{
                p=p-permutations[x][y]+1;
                if(p%2)cout<<1-arr[x][y]<<"\n";
                else cout<<arr[x][y]<<"\n";
            }
        }
    }
    return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details