#include <bits/stdc++.h>
using namespace std;
int calc(vector<string> &v, int n, int m){
int cnt = 0;
for(int i = 0; i < n; i++){
int a = 0, b= 0 ;
for(int j = 0; j < m; j++){
if(v[i][j] == '+') a++;
else b++;
}
cnt += (a > b);
}
for(int j = 0; j < m; j++){
int a = 0, b = 0;
for(int i = 0; i < n; i++){
if(v[i][j] == '-') a++;
else b++;
}
cnt += (a > b);
}
return cnt;
}
void printVec(vector<string> &v, int n, int m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << v[i][j];
}
cout << endl;
}
}
vector<string> rev(vector<string> v, int n, int m){
vector<string> a(m);
for(int i = 0; i < n; ++i){
for(int j = m - 1; j >= 0; --j){
if(v[i][j] == '+') a[m - j - 1].push_back('-');
else a[m - j - 1].push_back('+');
}
}
return a;
}
void GarniGeghard(int n, int m){
if (n + (m + 1) / 2 - 1 > m + (n + 1) / 2 - 1) {
cout << n + (m + 1) / 2 - 1 << endl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (j <= m / 2 + 1) cout << '+';
else cout << '-';
}
cout << "\n";
}
}
else {
cout << m + (n + 1) / 2 - 1 << endl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i <= n / 2 + 1) cout << '-';
else cout << '+';
}
cout << "\n";
}
}
}
void solve(){
int n, m; cin >> n >> m;
bool r = 0;
if (min(m, n) <= 3 || (n <= 4 && m <= 4)) {
GarniGeghard(n, m);
return;
}
if(n > m){
swap(n, m);
r = 1;
}
vector<string> v(n);
string s(m, '-');
v[0] = s;
if(n % 2 == 0 && n > 1) v[1] = s;
string a(m / 2 + 1, '+'), b(m - (m / 2 + 1), '-');
for(int i = 1 + (1 - (n % 2)); i < n; i++){
if(i % 2) v[i] = a + b;
else v[i] = b + a;
}
if(r){
v = rev(v, n, m);
swap(n, m);
}
int res = calc(v, n, m);
if(res < max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1)){
GarniGeghard(n, m);
return;
}
cout << calc(v, n, m) << endl;
// if(!r) printVec(v, n, m);
printVec(v, n, m);
}
int main(){
int t; cin >> t; while(t--)
solve();
}
# |
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 |
2 ms |
212 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 |
2 ms |
212 KB |
Output is correct |
4 |
Incorrect |
6 ms |
340 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
1364 KB |
Output is correct |
2 |
Correct |
31 ms |
2016 KB |
Output is correct |
3 |
Correct |
38 ms |
3532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
1320 KB |
Wrong answer in test 6 6: 8 < 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2 ms |
212 KB |
Output is correct |
4 |
Incorrect |
6 ms |
340 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |