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 n, m;
void sol() {
cin >> n >> m;
if (m == 2) {
// if (n < m) {
cout << n << "\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << "+";
}
cout << "\n";
}
// }
}else {
char arr[n][m];
int tooll[m] = {0};
int hed = 0;
if (n % 2 == 0) hed = n/2-1;
else hed = n/2;
int mm = m/2+1;
int niit = m;
for (int i = 0; i < n; i++) {
bool k = false;
if (i % 2 == 0) {
//zuun
for (int j = 0, mmm = mm; j < m; j++) {
if (mmm > 0 && tooll[j] < hed) {
arr[i][j] = '+';
tooll[j]++;
mmm--;
}else {
if (mmm == 0 && k == false) {
k = true;
}
arr[i][j] = '-';
}
}
}else {
//baruun
for (int j = m-1, mmm = mm; j >= 0; j--) {
if (mmm > 0 && tooll[j] < hed) {
arr[i][j] = '+';
mmm--;
tooll[j]++;
}else {
if (mmm == 0 && k == false) {
k = true;
}
arr[i][j] = '-';
}
}
}
if (k) niit++;
}
cout << niit << "\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << arr[i][j];
}
cout << "\n";
}
cout << "\n";
}
}
int main () {
int t;
cin >> t;
while (t--) sol();
}
// + + + + + + - - - -
// - - - - + + + + + +
// + + + + - - + + - -
// - - - - - - - - + +
// - - - - - - - - - -
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |