#include<bits/stdc++.h>
using namespace std ;
int main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
int t ;
cin >> t ;
while(t--)
{
int n, m, mx = 0 ;
cin >> n >> m ;
char c[n][m], ans[n][m] ;
if(n * m <= 16)
{
for(int x = 0 ; x < (1 << (n * m)) ; x++)
{
int st[m] = {}, str[n] = {}, sum = 0 ;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
if(x & (1 << (i * m + j)))
{
str[i]++ ;
c[i][j] = '+' ;
}
else
{
st[j]++ ;
c[i][j] = '-' ;
}
for(int i = 0 ; i < n ; i++)
if(str[i] > m / 2)sum++ ;
for(int i = 0 ; i < m ; i++)
if(st[i] > n / 2)sum++ ;
if(mx < sum)
{
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
ans[i][j] = c[i][j] ;
}
mx = max(mx, sum) ;
}
cout << mx << '\n' ;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
cout << ans[i][j] ;
cout << '\n' ;
}
continue ;
}
if(min(n, m) == 1)
{
if(n == 1)
{
cout << m << '\n' ;
for(int i = 0 ; i < m ; i++)
ans[0][i] = '-' ;
}
else
{
cout << n << '\n' ;
for(int i = 0 ; i < n ; i++)
ans[i][0] = '+' ;
}
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
cout << ans[i][j];
cout << '\n' ;
}
continue ;
}
if(min(n, m) == 2)
{
if(n == 2)
{
cout << m << '\n' ;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
ans[i][j] = '-' ;
}
else
{
cout << n << '\n' ;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
ans[i][j] = '+' ;
}
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
cout << ans[i][j];
cout << '\n' ;
}
continue ;
}
if(min(n, m) == 3)
{
if(n == 3)
{
for(int i = 0 ; i < n - 1 ; i++)
for(int j = 0 ; j < m ; j++)
ans[i][j] = '-' ;
for(int i = 0 ; i < m ; i++)
ans[n - 1][i] = '+' ;
}
else
{
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m - 1 ; j++)
ans[i][j] = '+' ;
for(int i = 0 ; i < n ; i++)
ans[i][m - 1] = '-' ;
}
cout << max(n, m) + 1 << '\n' ;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
cout << ans[i][j] ;
cout << '\n' ;
}
continue ;
}
if(n % 2 && m % 2)
{
if(n > m)
{
mx = n + m / 2 ;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
if(j % 2 == 0)ans[i][j] = '+' ;
else ans[i][j] = '-' ;
}
else
{
mx = m + n / 2 ;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
if(i % 2)ans[i][j] = '+' ;
else ans[i][j] = '-' ;
}
cout << mx << '\n' ;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
cout << ans[i][j] ;
cout << '\n' ;
}
continue ;
}
}
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
320 KB |
Output is correct |
3 |
Correct |
40 ms |
324 KB |
Output is correct |
4 |
Incorrect |
54 ms |
320 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
1308 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
852 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
320 KB |
Output is correct |
3 |
Correct |
40 ms |
324 KB |
Output is correct |
4 |
Incorrect |
54 ms |
320 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |