답안 #649876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
649876 2022-10-11T13:51:35 Z inksamurai Spirale (COCI18_spirale) C++17
72 / 80
1000 ms 2296 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];
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){
		vi usd(h*w);
		int sx,sy,t;
		cin>>sx>>sy>>t;
		sx-=1,sy-=1;
		a[sx][sy]=1;
		usd[sx*w+sy]=1;
		int _last=1;
		int ai=1;
		int now=0,cnt=0;
		int dir=0;
		while(1){
			bool pok=0;
			rep(i,h)rep(j,w)if(!usd[i*w+j])pok=1;
			if(!pok) break;
			ai+=1;
			if(ai>h*w*h*w*2) break;
			if(!t) sx+=di[dir];
			else sx+=di1[dir];
			if(!t) sy+=dj[dir];
			else sy+=dj1[dir];
			if(ok(sx,sy)){
				usd[sx*w+sy]=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";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 2 ms 2260 KB Output is correct
6 Correct 42 ms 2296 KB Output is correct
7 Correct 3 ms 2260 KB Output is correct
8 Correct 3 ms 2260 KB Output is correct
9 Execution timed out 1093 ms 2260 KB Time limit exceeded
10 Correct 98 ms 2292 KB Output is correct