답안 #144447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144447 2019-08-16T21:29:55 Z Ort Spirale (COCI18_spirale) C++11
80 / 80
40 ms 380 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ALL(c) (c).begin(),(c).end()
#define sz(a) ((int)(a.size()))
#define ll long long
#define LINF (ll)1e18
#define INF (int)1e9
#define MINF 0x3F3F3F3F
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
#define MOD 1000000007
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAX 60
#define watch(x) cerr<<#x<<" = "<<(x)<<endl;

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int mat[MAX][MAX];

int n, m, k;

int write(int sy, int sx, int val) {
	if(sy<0 || sx<0 || sy>=n || sx>=m) return 0;
	mat[sy][sx] = min(mat[sy][sx], val);
	return 1;
}

void write_spiral_clockwise(int sy, int sx, int val, int fill) {
	int up = 1, right = 1, down = 2, left = 2;
	mat[sy][sx] = val++;
	while(fill<(n*m)) {
		for(int i=0;i<up;i++) sy--, fill += write(sy, sx, val++);
		for(int i=0;i<right;i++) sx++, fill += write(sy, sx, val++);
		for(int i=0;i<down;i++) sy++, fill += write(sy, sx, val++);
		for(int i=0;i<left;i++) sx--, fill += write(sy, sx, val++);
		up += 2; right += 2; down += 2, left += 2;
	}
}

void write_spiral_counter_clockwise(int sy, int sx, int val, int fill) {
	int up = 1, right = 2, down = 2, left = 1;
	mat[sy][sx] = val++;
	while(fill<(n*m)) {
		for(int i=0;i<up;i++) sy--, fill += write(sy, sx, val++);
		for(int i=0;i<left;i++) sx--, fill += write(sy, sx, val++);
		for(int i=0;i<down;i++) sy++, fill += write(sy, sx, val++);
		for(int i=0;i<right;i++) sx++, fill += write(sy, sx, val++);
		up += 2; right += 2; down += 2, left += 2;
	}
}


int main() {
	IO;
	int x, y, t;
	MEM(mat,MINF);
	cin >> n >> m >> k;
	while(k--) {
		cin >> x >> y >> t; y--; x--; swap(x, y);
		if(t) write_spiral_counter_clockwise(y, x, 1, 1);
		else write_spiral_clockwise(y, x, 1, 1);
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++)
			cout << mat[i][j] << " ";
		cout << "\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 40 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct