답안 #761456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761456 2023-06-19T16:46:31 Z US3RN4M3 Gardening (RMI21_gardening) C++17
100 / 100
68 ms 796 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int arr[200000];

ll w, h;
int col;

inline int & get(int x, int y) {
	return arr[x*h + y];
}

pair<ll, ll> possible_range(ll n, ll m) {
	return {max(n, m) / 2, (n * m) / 4};
}

bool fits(ll n, ll m, ll k) {
	pair<ll, ll> range = possible_range(n, m);
	return (range.first <= k && k <= range.second && k != range.second - 1);
}

bool create_rect(ll sx, ll sy, ll n, ll m, ll k) {
	if(k == (n * m) / 4) {
		for(int i = 0; i < n; i += 2) for(int j = 0; j < m; j += 2) {
			col++;
			get(sx + i, sy + j) = col;
			get(sx + i + 1, sy + j) = col;
			get(sx + i, sy + j + 1) = col;
			get(sx + i + 1, sy + j + 1) = col;
		}
		return true;
	}
	if(n != 2 && m != 2 && fits(n - 2, m - 2, k - 1)) {
		col++;
		for(int i = 0; i < n; i++) {
			get(sx + i, sy) = col;
			get(sx + i, sy + m - 1) = col;
		}
		for(int i = 0; i < m; i++) {
			get(sx, sy + i) = col;
			get(sx + n - 1, sy + i) = col;
		}
		return create_rect(sx + 1, sy + 1, n - 2, m - 2, k - 1);
	}
	if(n != 2 && fits(n - 2, m, k - (m / 2))) {
		for(int i = 0; i < m; i += 2) {
			col++;
			get(sx, sy + i) = col;
			get(sx + 1, sy + i) = col;
			get(sx, sy + i + 1) = col;
			get(sx + 1, sy + i + 1) = col;
		}
		return create_rect(sx + 2, sy, n - 2, m, k - (m / 2));
	}
	if(m != 2 && fits(n, m - 2, k - (n / 2))) {
		for(int i = 0; i < n; i += 2) {
			col++;
			get(sx + i, sy) = col;
			get(sx + i, sy + 1) = col;
			get(sx + i + 1, sy) = col;
			get(sx + i + 1, sy + 1) = col;
		}
		return create_rect(sx, sy + 2, n, m - 2, k - (n / 2));
	}
	cout << "NO" << endl;
	return false;
}


void solve() {
	ll k;
	cin >> w >> h >> k;
	if(w * h > 200000 || w & 1 || h & 1) {
		cout << "NO" << endl;
		return;
	}
	col = 0;
	if(create_rect(0, 0, w, h, k)) {
		cout << "YES" << endl;
		for(int i = 0; i < w; i++) for(int j = 0; j < h; j++) cout << get(i, j) << " \n"[j == h - 1];
	}
}

main() {
	int t; cin >> t;
	while(t--)
		solve();
}

Compilation message

Main.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   85 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 648 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 648 KB Correct! Azusa and Laika like the garden :)
2 Correct 13 ms 576 KB Correct! Azusa and Laika like the garden :)
3 Correct 14 ms 596 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 648 KB Correct! Azusa and Laika like the garden :)
2 Correct 13 ms 576 KB Correct! Azusa and Laika like the garden :)
3 Correct 14 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Correct 12 ms 648 KB Correct! Azusa and Laika like the garden :)
5 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
2 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Correct 7 ms 560 KB Correct! Azusa and Laika like the garden :)
5 Correct 7 ms 568 KB Correct! Azusa and Laika like the garden :)
6 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 572 KB Correct! Azusa and Laika like the garden :)
8 Correct 7 ms 568 KB Correct! Azusa and Laika like the garden :)
9 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
10 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
11 Correct 7 ms 588 KB Correct! Azusa and Laika like the garden :)
12 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
13 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
2 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
3 Correct 3 ms 312 KB Correct! Azusa and Laika like the garden :)
4 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
5 Correct 4 ms 440 KB Correct! Azusa and Laika like the garden :)
6 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
7 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
8 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
9 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
10 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
11 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
12 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
13 Correct 3 ms 436 KB Correct! Azusa and Laika like the garden :)
14 Correct 4 ms 440 KB Correct! Azusa and Laika like the garden :)
15 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
16 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
17 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 648 KB Correct! Azusa and Laika like the garden :)
2 Correct 13 ms 576 KB Correct! Azusa and Laika like the garden :)
3 Correct 14 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Correct 12 ms 648 KB Correct! Azusa and Laika like the garden :)
5 Correct 12 ms 596 KB Correct! Azusa and Laika like the garden :)
6 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
8 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
9 Correct 7 ms 560 KB Correct! Azusa and Laika like the garden :)
10 Correct 7 ms 568 KB Correct! Azusa and Laika like the garden :)
11 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
12 Correct 7 ms 572 KB Correct! Azusa and Laika like the garden :)
13 Correct 7 ms 568 KB Correct! Azusa and Laika like the garden :)
14 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
15 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
16 Correct 7 ms 588 KB Correct! Azusa and Laika like the garden :)
17 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
18 Correct 7 ms 596 KB Correct! Azusa and Laika like the garden :)
19 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
20 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
21 Correct 3 ms 312 KB Correct! Azusa and Laika like the garden :)
22 Correct 4 ms 468 KB Correct! Azusa and Laika like the garden :)
23 Correct 4 ms 440 KB Correct! Azusa and Laika like the garden :)
24 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
25 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
26 Correct 4 ms 340 KB Correct! Azusa and Laika like the garden :)
27 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
28 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
29 Correct 2 ms 348 KB Correct! Azusa and Laika like the garden :)
30 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
31 Correct 3 ms 436 KB Correct! Azusa and Laika like the garden :)
32 Correct 4 ms 440 KB Correct! Azusa and Laika like the garden :)
33 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
34 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
35 Correct 3 ms 340 KB Correct! Azusa and Laika like the garden :)
36 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
37 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
38 Correct 10 ms 736 KB Correct! Azusa and Laika like the garden :)
39 Correct 11 ms 776 KB Correct! Azusa and Laika like the garden :)
40 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
41 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
42 Correct 10 ms 692 KB Correct! Azusa and Laika like the garden :)
43 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
44 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
45 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
46 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
47 Correct 10 ms 780 KB Correct! Azusa and Laika like the garden :)
48 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
49 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
50 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
51 Correct 9 ms 724 KB Correct! Azusa and Laika like the garden :)
52 Correct 10 ms 708 KB Correct! Azusa and Laika like the garden :)
53 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
54 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
55 Correct 10 ms 688 KB Correct! Azusa and Laika like the garden :)
56 Correct 10 ms 720 KB Correct! Azusa and Laika like the garden :)
57 Correct 10 ms 796 KB Correct! Azusa and Laika like the garden :)
58 Correct 10 ms 724 KB Correct! Azusa and Laika like the garden :)
59 Correct 10 ms 796 KB Correct! Azusa and Laika like the garden :)
60 Correct 10 ms 776 KB Correct! Azusa and Laika like the garden :)