답안 #648147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648147 2022-10-05T14:07:48 Z ymm Red-blue table (IZhO19_stones) C++17
15 / 100
28 ms 5968 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

bool edge(int n, int m)
{
	if (n == 1) {
		cout << m << '\n';
		Loop (i,0,m)
			cout << '-';
		cout << '\n';
		return 1;
	}
	if (m == 1) {
		cout << n << '\n';
		Loop (i,0,n)
			cout << '+' << '\n';
		return 1;
	}
	if (n == 2) {
		cout << m << '\n';
		Loop (i,0,m)
			cout << '-';
		cout << '\n';
		Loop (i,0,m)
			cout << '-';
		cout << '\n';
		return 1;
	}
	if (m == 2) {
		cout << n << '\n';
		Loop (i,0,n)
			cout << "++" << '\n';
		return 1;
	}
	if (n == 4) {
		cout << m+1 << '\n';
		Loop (i,0,3) {
			Loop (j,0,m)
				cout << '-';
			cout << '\n';
		}
		Loop (j,0,m)
			cout << '+';
		cout << '\n';
		return 1;
	}
	if (m == 4) {
		cout << n+1 << '\n';
		Loop (i,0,n)
			cout << "+++-" << '\n';
		return 1;
	}
	if (n == 6 && m == 6) {
		char s[] = {
			"++++--\n"
			"++++--\n"
			"+++-+-\n"
			"+++-+-\n"
			"+++--+\n"
			"+++--+\n"
		};
		cout << "9\n";
		cout << s;
		return 1;
	}
	return 0;
}

const int N = 2010;
int ans[N][N];

void myfill(int n, int m)
{
	Loop (i,0,n) {
		Loop (j,0,m)
			ans[i+1][j+1] = (i+j)%m < m/2? 1: 0;
	}
}

int mycount(int n, int m)
{
	int x = 0;
	Loop (i,0,n) {
		int cnt = 0;
		Loop (j,0,m)
			cnt += ans[i][j] == 1;
		x += cnt > m/2;
	}
	Loop (j,0,m) {
		int cnt = 0;
		Loop (i,0,n)
			cnt += ans[i][j] == 0;
		x += cnt > n/2;
	}
	return x;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	if (edge(n, m))
		return;
	Loop (j,0,m)
		ans[0][j] = 0;
	Loop (i,0,n)
		ans[i][0] = 1;
	if (n%2 == 0)
		Loop (j,0,m)
			ans[n-1][j] = 0;
	if (m%2 == 0)
		Loop (i,0,n)
			ans[i][m-1] = 1;
	myfill(n-1 & -2, m-1 & -2);
	cout << mycount(n, m) << '\n';
	Loop (i,0,n) {
		Loop (j,0,m)
			cout << "-+"[ans[i][j]];
		cout << '\n';
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
		solve();
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:119:10: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  119 |  myfill(n-1 & -2, m-1 & -2);
      |         ~^~
stones.cpp:119:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  119 |  myfill(n-1 & -2, m-1 & -2);
      |                   ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Wrong answer in test 4 3: 4 < 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Wrong answer in test 3 45: 25 < 46
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Wrong answer in test 4 3: 4 < 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 1676 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1876 KB Output is correct
2 Correct 23 ms 5968 KB Output is correct
3 Correct 21 ms 4584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Wrong answer in test 4 3: 4 < 5
3 Halted 0 ms 0 KB -