답안 #348426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348426 2021-01-15T01:58:30 Z Kevin_Zhang_TW Red-blue table (IZhO19_stones) C++17
100 / 100
41 ms 2412 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 1010;

int n, m;
char w[MAX_N][MAX_N];

#define rev(w) (char)('+' ^ '-' ^ (w))

void solve(int n, int m) {
	bool rot = false;

	DE(n, m);

	if (n > m) rot = true, swap(n, m);

	auto gen = [&]() {
		for (int i = 0;i < n;++i) for (int j = 0;j < m;++j)
			w[i][j] = '-';

		int res = m;

		vector<int> cnt(m);

		// height is atmost mxh

		int filwid = m / 2 + 1, needh = n / 2 + 1, mxh = n - needh;

		for (int i = 0, H = 0;i < n;++i) {
			bool todo = true;
			for (int j = 0;j < filwid;++j) 
				if ((++cnt[ (H + j) % m ]) > mxh)
					todo = false;

			if (!todo) break;

			for (int j = 0;j < filwid;++j) 
				w[i][ (H + j) % m ] = '+';

			H = (H + filwid) % m;
			++res;
		}
		return res;
	};

	int cnt = gen();

	cout << cnt << '\n';

	if (rot) {
		swap(n, m);
		for (int i = 0;i < n;++i) {
			for (int j = 0;j < m;++j) 
				cout << rev(w[j][i]);
			cout << '\n';
		}
	}
	else {
		for (int i = 0;i < n;++i) {
			for (int j = 0;j < m;++j)
				cout << w[i][j] ;
			cout << '\n';
		}
	}
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
//  	for (int i = 1;i <= 4;++i) for (int j = 1;j <= 4;++j)
//  		solve(i, j);
  	int T;
  	cin >> T;
  	while (T--) {
  		int n, m;
  		cin >> n >> m;
  		solve(n, m);
 	}
}

Compilation message

stones.cpp: In function 'void solve(int, int)':
stones.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
stones.cpp:28:2: note: in expansion of macro 'DE'
   28 |  DE(n, m);
      |  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1516 KB Output is correct
2 Correct 36 ms 2028 KB Output is correct
3 Correct 35 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1516 KB Output is correct
2 Correct 34 ms 2156 KB Output is correct
3 Correct 32 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 41 ms 1516 KB Output is correct
6 Correct 36 ms 2028 KB Output is correct
7 Correct 35 ms 1900 KB Output is correct
8 Correct 41 ms 1516 KB Output is correct
9 Correct 34 ms 2156 KB Output is correct
10 Correct 32 ms 1644 KB Output is correct
11 Correct 10 ms 620 KB Output is correct
12 Correct 36 ms 1644 KB Output is correct
13 Correct 33 ms 1644 KB Output is correct
14 Correct 26 ms 1388 KB Output is correct
15 Correct 40 ms 2412 KB Output is correct
16 Correct 30 ms 1900 KB Output is correct
17 Correct 14 ms 1132 KB Output is correct