답안 #167489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167489 2019-12-08T17:05:45 Z Lightning Red-blue table (IZhO19_stones) C++14
100 / 100
35 ms 3320 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2000;
const int INF = 1e9;

char a[N][N];
int cnt[N];

void solve(int n, int m) {
	if(n >= m) {
		fo(i, 1, n, 1) {
			fo(j, 1, m, 1) {
				a[i][j] = '+';
			}
		}
		int need = (n / 2 + 1);
		int mx = m - (m / 2 + 1);
		int pos = 1;
		int ans = 0;
		fo(j, 1, m, 1) {
			bool ok = 1;
			fo(it, 1, need, 1) {
				if(cnt[pos] < mx) {
					a[pos][j] = '-';	
					++cnt[pos];
					++pos;
					if(pos == n + 1) pos = 1;
				} else ok = 0;
			}
			ans += ok;
		}
		cout << n + ans <<'\n';
		fo(i, 1, n, 1) {
			cnt[i] = 0;
			fo(j, 1, m, 1) {
				cout << a[i][j];
			}
			cout << '\n';
		}
	} else {
		fo(i, 1, n, 1) {
			fo(j, 1, m, 1) {
				a[i][j] = '-';
			}
		}
		int need = (m / 2 + 1);
		int mx = n - (n / 2 + 1);
		int pos = 1;
		int ans = 0;
		fo(i, 1, n, 1) {
			bool ok = 1;
			fo(it, 1, need, 1) {
				if(cnt[pos] < mx) {
					a[i][pos] = '+';	
					++cnt[pos];
					++pos;
					if(pos == m + 1) pos = 1;
				} else ok = 0;
			}
			ans += ok;
		}
		cout << m + ans <<'\n';
		fo(i, 1, n, 1) {
			fo(j, 1, m, 1) {
				cout << a[i][j];
				cnt[j] = 0;
			}
			cout << '\n';
		}
	}
}

int t;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> t;
	fo(it, 1, t, 1) {
		int n, m;
		cin >> n >> m;
		solve(n, m);
	}
	return 0;
}









# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1528 KB Output is correct
2 Correct 29 ms 2680 KB Output is correct
3 Correct 30 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1656 KB Output is correct
2 Correct 28 ms 2680 KB Output is correct
3 Correct 26 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 31 ms 1528 KB Output is correct
6 Correct 29 ms 2680 KB Output is correct
7 Correct 30 ms 3064 KB Output is correct
8 Correct 30 ms 1656 KB Output is correct
9 Correct 28 ms 2680 KB Output is correct
10 Correct 26 ms 2296 KB Output is correct
11 Correct 9 ms 632 KB Output is correct
12 Correct 28 ms 2680 KB Output is correct
13 Correct 29 ms 2964 KB Output is correct
14 Correct 24 ms 2552 KB Output is correct
15 Correct 35 ms 3320 KB Output is correct
16 Correct 24 ms 2728 KB Output is correct
17 Correct 13 ms 2040 KB Output is correct