#include <bits/stdc++.h>
using namespace std;
#define debug(v) cerr<<#v" = "<<(v)<<"\n"
#define fst first
#define snd second
#define gcd(x,y) __gcd(x,y);
#define OnlineJudge(s) freopen((s".in"),"r",stdin); freopen((s".out"),"w",stdout);
#define fastIO() cin.tie(0)->sync_with_stdio(0);cin.exceptions(cin.failbit);
#define boolsolve() cout<<(solve()?"Yes":"No");
using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vpll=vector<pll>;
using vvll=vector<vll>;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll MAXN=5e5+100;
ll fexp(ll a,ll b,ll m=MOD){
	ll r=1;
	for(a%=m;b;b>>=1,a=(a*a)%m)if(b&1)r=(r*a)%m;
	return r;
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
vvll d(2,vll(20001,0));
void getd(){
    ll v=7, c=3;
    d[1][1]=-1;
    d[0][2]=1;
    d[1][3]=1;
    d[1][4]=1;
    d[0][5]=-1;
    d[0][6]=-1;
    while(v<=10000){
        for(int i=v; i<v+c; i++) d[1][i]=-1;
        v+=c;
        for(int i=v; i<v+c; i++) d[0][i]=1;
        v+=c; c++;
        for(int i=v; i<v+c; i++) d[1][i]=1;
        v+=c;
        for(int i=v; i<v+c; i++) d[0][i]=-1;
        v+=c; c++;
    }
}
void solve(){
    ll n, m, k, c=0, x, y, t;
    queue<tuple<ll,ll,ll,ll>> q;
    cin >> n >> m >> k;
    vvll A(n,vll(m,-1));
    for(int i=0; i<k; i++){
        cin >> y >> x >> t; x--; y--;
        if(t==0) q.push({x,y,1,1});
        else q.push({x,y,-1,1});
    }
    while(c<n*m){
        auto [a,b,dir,v]=q.front(); q.pop();
        if(a>=0 && b<n && b>=0 && a<m && A[b][a]==-1){
            A[b][a]=v;
            c++;
        }
        a+=dir*d[0][v]; b+=d[1][v];
        q.push({a,b,dir,v+1});
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++) cout << A[i][j] << " ";
        cout << "\n";
    }
}
int main(){
    fastIO();
    getd();
    //OnlineJudge("")
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
        //cout << "\n";
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |