Submission #648160

# Submission time Handle Problem Language Result Execution time Memory
648160 2022-10-05T14:44:56 Z ymm Red-blue table (IZhO19_stones) C++17
69 / 100
25 ms 7744 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 <= m && n <= 4) {
		cout << m+1 << '\n';
		Loop (i,0,n-1) {
			Loop (j,0,m)
				cout << '-';
			cout << '\n';
		}
		Loop (j,0,m)
			cout << '+';
		cout << '\n';
		return 1;
	}
	if (m <= n && m <= 4) {
		cout << n+1 << '\n';
		Loop (i,0,n) {
			Loop (j,0,m-1)
				cout << '+';
			cout << "-\n";
		}
		return 1;
	}
	if (n == 5 && m%2 == 0) {
		cout << m+3 << '\n';
		Loop (i,0,2) {
			Loop (j,0,m)
				cout << '-';
			cout << '\n';
		}
		Loop (j,0,m/2+1)
			cout << '+';
		Loop (j,m/2+1,m)
			cout << '-';
		cout << '\n';
		Loop (j,0,m/2-1)
			cout << '-';
		Loop (j,m/2-1,m)
			cout << '+';
		cout << '\n';
		Loop (j,0,m/2-1)
			cout << '+';
		cout << "--++";
		Loop (j,m/2+3,m)
			cout << '-';
		cout << '\n';
		return 1;
	}
	if (m == 5 && n%2 == 0) {
		cout << n+3 << '\n';
		Loop (i,0,n/2-1)
			cout << "++-+-\n";
		cout << "++--+\n";
		cout << "++--+\n";
		cout << "+++--\n";
		cout << "+++--\n";
		Loop (i,n/2+3,n)
			cout << "+++-+\n";
		return 1;
	}
	if (n == 8 && m%2 == 0 && m >= 10) {
		cout << m+5 << '\n';
		Loop (i,0,3) {
			Loop (j,0,m)
				cout << '-';
			cout << '\n';
		}
		Loop (j,0,m/2-1)
			cout << '-';
		Loop (j,m/2-1,m)
			cout << '+';
		cout << '\n';
		Loop (j,0,m/2+1)
			cout << '+';
		Loop (j,m/2+1,m)
			cout << '-';
		cout << '\n';
		Loop (j,0,m/2-3)
			cout << '-';
		cout << "++--";
		Loop (j,m/2+1,m)
			cout << '+';
		cout << '\n';
		Loop (j,0,m/2+1)
			cout << '+';
		Loop (j,m/2+1,m)
			cout << '-';
		cout << '\n';
		Loop (j,0,m/2-5)
			cout << '-';
		cout << "++----";
		Loop (k,m/2+1,m)
			cout << '+';
		cout << '\n';
		return 1;
	}
	if (m == 8 && n%2 == 0 && n >= 10) {
		cout << n+5 << '\n';
		Loop (i,0,n/2-1)
			cout << "+++-+-+-\n";
		cout << "+++--+-+\n";
		cout << "+++--+-+\n";
		cout << "++++---+\n";
		cout << "++++---+\n";
		cout << "++++-+--\n";
		cout << "++++-+--\n";
		Loop (i,n/2+5,n)
			cout << "++++-+-+\n";
		return 1;
	}
	if (n == 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] = j < m/2? (i&1): !(i&1);
	}
}

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:209:10: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  209 |  myfill(n-1 & -2, m-1 & -2);
      |         ~^~
stones.cpp:209:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  209 |  myfill(n-1 & -2, m-1 & -2);
      |                   ~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1720 KB Output is correct
2 Correct 24 ms 6720 KB Output is correct
3 Correct 22 ms 7744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1888 KB Output is correct
2 Correct 24 ms 5940 KB Output is correct
3 Correct 20 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 25 ms 1720 KB Output is correct
6 Correct 24 ms 6720 KB Output is correct
7 Correct 22 ms 7744 KB Output is correct
8 Correct 24 ms 1888 KB Output is correct
9 Correct 24 ms 5940 KB Output is correct
10 Correct 20 ms 4564 KB Output is correct
11 Incorrect 7 ms 596 KB Wrong answer in test 9 18: 24 < 25
12 Halted 0 ms 0 KB -