#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';
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8284 KB |
Output is correct |
2 |
Correct |
6 ms |
8124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
8344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8284 KB |
Output is correct |
2 |
Correct |
6 ms |
8124 KB |
Output is correct |
3 |
Correct |
96 ms |
8344 KB |
Output is correct |
4 |
Correct |
164 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
9296 KB |
Output is correct |
2 |
Correct |
33 ms |
9040 KB |
Output is correct |
3 |
Correct |
37 ms |
9160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
7764 KB |
Output is correct |
2 |
Correct |
31 ms |
8004 KB |
Output is correct |
3 |
Correct |
28 ms |
7504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8284 KB |
Output is correct |
2 |
Correct |
6 ms |
8124 KB |
Output is correct |
3 |
Correct |
96 ms |
8344 KB |
Output is correct |
4 |
Correct |
164 ms |
8540 KB |
Output is correct |
5 |
Correct |
159 ms |
9296 KB |
Output is correct |
6 |
Correct |
33 ms |
9040 KB |
Output is correct |
7 |
Correct |
37 ms |
9160 KB |
Output is correct |
8 |
Correct |
38 ms |
7764 KB |
Output is correct |
9 |
Correct |
31 ms |
8004 KB |
Output is correct |
10 |
Correct |
28 ms |
7504 KB |
Output is correct |
11 |
Correct |
270 ms |
8728 KB |
Output is correct |
12 |
Correct |
33 ms |
8272 KB |
Output is correct |
13 |
Correct |
31 ms |
9040 KB |
Output is correct |
14 |
Correct |
25 ms |
8792 KB |
Output is correct |
15 |
Correct |
38 ms |
9304 KB |
Output is correct |
16 |
Correct |
26 ms |
9296 KB |
Output is correct |
17 |
Correct |
13 ms |
7260 KB |
Output is correct |