Submission #649882

# Submission time Handle Problem Language Result Execution time Memory
649882 2022-10-11T13:57:42 Z inksamurai Spirale (COCI18_spirale) C++17
80 / 80
97 ms 2288 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3yqVz8E ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

const int _n=711,inf=1e9;

int a[_n][_n];
int tbl[_n][_n][4];

void gap(){
	rep(i,_n)rep(j,_n)a[i][j]=inf;
}


int h,w,n;
bool contains(){
	rep(i,h){
		rep(j,w){
			if(a[i][j]==-1)return 1;
		}
	}
	return 0;
}

const int di[]={-1,0,1,0};
const int dj[]={0,1,0,-1};

const int di1[]={-1,0,1,0};
const int dj1[]={0,-1,0,1};

bool ok(int x,int y){
	return x>=0 and y>=0 and x<h and y<w;
}

signed main(){
_3yqVz8E;
	gap();
	cin>>h>>w>>n;
	rep(i,n){
		int sx,sy,t;
		cin>>sx>>sy>>t;
		sx-=1,sy-=1;
		a[sx][sy]=1;
		int visited=0;
		int _last=1;
		int ai=1;
		int now=0,cnt=0;
		int dir=0;
		rep(_,5*h*w){
			if(visited==h*w) break;
			ai+=1;
			if(!t) sx+=di[dir];
			else sx+=di1[dir];
			if(!t) sy+=dj[dir];
			else sy+=dj1[dir];
			if(ok(sx,sy)){
				visited+=1;
				a[sx][sy]=min(a[sx][sy],ai);
			}
			now+=1;
			if(now==_last){
				now=0;
				dir++;
				dir%=4;
				cnt+=1;
				if(cnt==2){
					cnt=0;
					_last+=1;
				}
			}
		}
	}
	rep(i,h){
		rep(j,w){
			cout<<a[i][j]<<" ";
		}
		cout<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2216 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 2 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 97 ms 2288 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct