#include <iostream>
#include <cstring>
using namespace std;
const int N = 1005;
int T;
int cont[N];
bool marked[N][N];
int solve(int n, int m)
{
int maxN = (n - 1) / 2, minM = m / 2 + 1, index = 1, rowCont = 0;
for(int i = 1; i <= n; i++)
{
int j;
for(j = 1; j <= minM; j++)
{
while(cont[index] >= maxN && index <= m)
index++;
if(index > m)
break;
cont[index]++;
marked[i][index] = 1;
if(index == m)
index = 1;
else
index++;
}
if(j == minM + 1)
rowCont++;
}
/*
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
cout << marked[i][j] << ' ';
cout << '\n';
}
*/
return m + rowCont;
}
void print(int n, int m, int val, bool inverted)
{
cout << val << '\n';
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(!inverted)
cout << (marked[i][j] ? "+" : "-");
else
cout << (marked[j][i] ? "-" : "+");
}
cout << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> T;
while(T--)
{
memset(marked, 0, sizeof marked);
memset(cont, 0, sizeof cont);
int n, m;
cin >> n >> m;
if(n <= m)
print(n, m, solve(n, m), 0);
else
print(n, m, solve(m, n), 1);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1216 KB |
Output is correct |
3 |
Correct |
9 ms |
1228 KB |
Output is correct |
4 |
Correct |
14 ms |
1336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2300 KB |
Output is correct |
2 |
Correct |
21 ms |
2112 KB |
Output is correct |
3 |
Correct |
19 ms |
2124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2232 KB |
Output is correct |
2 |
Correct |
18 ms |
2024 KB |
Output is correct |
3 |
Correct |
19 ms |
1984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
1 ms |
1216 KB |
Output is correct |
3 |
Correct |
9 ms |
1228 KB |
Output is correct |
4 |
Correct |
14 ms |
1336 KB |
Output is correct |
5 |
Correct |
34 ms |
2300 KB |
Output is correct |
6 |
Correct |
21 ms |
2112 KB |
Output is correct |
7 |
Correct |
19 ms |
2124 KB |
Output is correct |
8 |
Correct |
31 ms |
2232 KB |
Output is correct |
9 |
Correct |
18 ms |
2024 KB |
Output is correct |
10 |
Correct |
19 ms |
1984 KB |
Output is correct |
11 |
Correct |
31 ms |
1436 KB |
Output is correct |
12 |
Correct |
22 ms |
1988 KB |
Output is correct |
13 |
Correct |
18 ms |
2124 KB |
Output is correct |
14 |
Correct |
13 ms |
1868 KB |
Output is correct |
15 |
Correct |
20 ms |
2276 KB |
Output is correct |
16 |
Correct |
15 ms |
1996 KB |
Output is correct |
17 |
Correct |
7 ms |
1612 KB |
Output is correct |