답안 #990480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990480 2024-05-30T13:42:35 Z ToniB Red-blue table (IZhO19_stones) C++17
100 / 100
54 ms 2228 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
const int N = 1001;

int t, n, m;
bool ans[N][N];

int main(){
//	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> t;
	while (t--) {
		cin >> n >> m;
		bool swp = 0;
		if (n > m) {
			swap(n, m);
			swp = 1;
		}

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) ans[i][j] = 0;
		}
		
		int sum = m, mx = (n - 1) / 2;
		multiset<pii> ms;
		queue<pii> tmp;
		for (int i = 0; i < m; ++i) ms.insert({0, i});
		
		for (int i = 0; i < n; ++i) {
			vector<int> cols;
			bool bad = 0;
			while (cols.size() < m / 2 + 1) {
				auto it = ms.begin();
				int idx = (*it).second, cnt = (*it).first;
				ms.erase(it);
				if (cnt == mx) {
					bad = 1; break;
				}
				cols.push_back(idx);
				tmp.push({cnt + 1, idx});
			}
			if (bad) break;
			for (int j : cols) ans[i][j] = 1;
			while (!tmp.empty()) {
				ms.insert(tmp.front());
				tmp.pop();
			}
			++sum;
		}
		
		cout << sum << '\n';

		if (swp) {
			for (int i = 0; i < m; ++i) {
				for (int j = 0; j < n; ++j) {
					if (ans[j][i]) cout << '-';
					else cout << '+';
				} cout << '\n';
			}
		} else {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					if (ans[i][j]) cout << '+';
					else cout << '-';
				} cout << '\n';
			}
		}

	}
	return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:34:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |    while (cols.size() < m / 2 + 1) {
      |           ~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 1352 KB Output is correct
2 Correct 53 ms 2104 KB Output is correct
3 Correct 46 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 1492 KB Output is correct
2 Correct 44 ms 1872 KB Output is correct
3 Correct 41 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 47 ms 1352 KB Output is correct
6 Correct 53 ms 2104 KB Output is correct
7 Correct 46 ms 1884 KB Output is correct
8 Correct 51 ms 1492 KB Output is correct
9 Correct 44 ms 1872 KB Output is correct
10 Correct 41 ms 1616 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 45 ms 1624 KB Output is correct
13 Correct 46 ms 1616 KB Output is correct
14 Correct 33 ms 1372 KB Output is correct
15 Correct 54 ms 2228 KB Output is correct
16 Correct 40 ms 1872 KB Output is correct
17 Correct 19 ms 1112 KB Output is correct