Submission #40395

# Submission time Handle Problem Language Result Execution time Memory
40395 2018-01-31T13:16:14 Z szawinis Spirale (COCI18_spirale) C++14
80 / 80
86 ms 788 KB
#include <bits/stdc++.h>
using namespace std;

int n, m, k, f[51][51];
int dx[4] = {-1, 0, 1, 0}, dy[2][4] = {{0, 1, 0, -1}, {0, -1, 0, 1}};
int main() {
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) f[i][j] = 1e9;
	for(int z = 0, x, y, t; z < k; z++) {
		scanf("%d %d %d", &x, &y, &t);
		f[x][y] = 1;
		int elapsed = 1;
		for(int i = 1; i <= 200; i++) for(int j = 0; j < i+1 >> 1; j++) {
			++elapsed;
			x += dx[(i-1) % 4];
			y += dy[t][(i-1) % 4];
			if(x >= 1 && x <= n && y >= 1 && y <= m) f[x][y] = min(elapsed, f[x][y]);
		}
	}
	for(int i = 1; i <= n; i++, printf("\n")) for(int j = 1; j <= m; j++) printf("%d ", f[i][j]);
}

Compilation message

spirale.cpp: In function 'int main()':
spirale.cpp:13:53: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   for(int i = 1; i <= 200; i++) for(int j = 0; j < i+1 >> 1; j++) {
                                                     ^
spirale.cpp:7:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &m, &k);
                               ^
spirale.cpp:10:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &x, &y, &t);
                                ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 86 ms 756 KB Output is correct
10 Correct 2 ms 788 KB Output is correct