# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
868140 | heeheeheehaaw | Red-blue table (IZhO19_stones) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int b[1005][1005];
int ra, rb;
int main()
{
int t, n, m;
cin>>t;
while(t--)
{
cin>>n>>m;
ra = 0, rb = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
a[i][j] = 0, b[i][j] = 1;
int ln = m / 2;
if(m % 2 == 0) ln--;
int lm = n / 2;
if(n % 2 == 0) lm--;
queue<pair<int, int>> q;
for(int i = 1; i <= n; i++)
if(ln > 0)
q.push({ln, i});
for(int j = 1; j <= m; j++)
{
int nr = n - lm;
while(nr-- && (int)q.size())
{
pair<int, int> curr = q.front();
q.pop();
a[curr.second][j] = 1;
if(curr.first > 1)
q.push({curr.first - 1, curr.second});
}
}
while((int)q.size())
q.pop();
for(int j = 1; j <= m; j++)
if(lm > 0)
q.push({lm, j});
for(int i = 1; i <= n; i++)
{
int nr = m - ln;
while(nr-- && (int)q.size())
{
pair<int, int> curr = q.front();
q.pop();
b[i][curr.second] = 0;
if(curr.first > 1)
q.push({curr.first - 1, curr.second});
}
}
for(int i = 1; i <= n; i++)
{
int nr0 = 0, nr1 = 0;
for(int j = 1; j <= m; j++)
if(a[i][j] == 0) nr0++;
else nr1++;
if(nr0 > nr1) ra++;
}
for(int j = 1; j <= m; j++)
{
int nr0 = 0, nr1 = 0;
for(int i = 1; i <= n; i++)
if(a[i][j] == 0) nr0++;
else nr1++;
if(nr0 < nr1) ra++;
}
for(int i = 1; i <= n; i++)
{
int nr0 = 0, nr1 = 0;
for(int j = 1; j <= m; j++)
if(b[i][j] == 0) nr0++;
else nr1++;
if(nr0 > nr1) rb++;
}
for(int j = 1; j <= m; j++)
{
int nr0 = 0, nr1 = 0;
for(int i = 1; i <= n; i++)
if(b[i][j] == 0) nr0++;
else nr1++;
if(nr0 < nr1) rb++;
}
if(ra < rb)
swap(a, b);
cout<<max(ra, rb)<<'\n';a
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(a[i][j] == 0)
cout<<"+";
else
cout<<"-";
}
cout<<'\n';
}
}
return 0;
}