답안 #144785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144785 2019-08-17T17:58:23 Z tnbs10 Spirale (COCI18_spirale) C++14
80 / 80
135 ms 632 KB
// HONI 17/18, kolo 5, zad.5 - spirale
// http://hsin.hr/honi/arhiva/2017_2018/kolo5_zadaci.pdf

#include <bits/stdc++.h>
#define MAXN 200
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(c) (c).begin(), (c).end()
using namespace std;

ll n, m, k, x, y, t, a[MAXN][MAXN], sred = 70, smjer, sm[5];

void print(ll arr[MAXN][MAXN], int r, int s) {
	for (int i = sred; i < sred + r; i++) {
		for (int j = sred; j < sred + s; ++j) {
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}
}

void spirc(int x, int y, int t) {
	int curr = 1; ll prati = 1; smjer = 0;
	while (x > 15 and x < 175 and y > 15 and y < 175) {
		/*cout << x << " " << y << " " << " -> " << prati << "\n";*/
		if (!a[x][y]) a[x][y] = prati;
		else a[x][y] = min(prati, a[x][y]);
		if (smjer % 4 == 0) x--;
		else if (smjer % 4 == 1 and !t) y++;
		else if (smjer % 4 == 1) y--;
		else if (smjer % 4 == 2) x++;
		else if (smjer % 4 == 3 and !t) y--;
		else y++;
		if (!--sm[smjer % 4]) {
			sm[smjer % 4] = curr + 2;
			curr = sm[++smjer % 4];
		}
		++prati;
	}
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> m >> k;
	for (int i = 0; i < k; i++) {
		cin >> x >> y >> t;
		x--; y--;
		sm[0] = sm[1] = 1;
		sm[2] = sm[3] = 2;
		spirc(x + sred, y + sred, t);
	}
	print(a, n, m);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 135 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct