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;
#define ff first
#define ss second
const int N = 1e3 + 5;
priority_queue <pair <int, int>> q;
char jog[N][N], jog1[N][N];
int main() {
// freopen ("input.txt", "r", stdin);
int t;
cin >> t;
while ( t-- ) {
int n, m;
cin >> n >> m;
// cout << "test cases : " << n << " " << m << endl;
bool tr = 0;
if (n < m) {
swap (n, m);
tr = 1;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
jog[i][j] = '+';
}
}
int a = n / 2 + 1;
int b = (m - 1) / 2;
int ans = n + ((n * b) / a);
for (int i = 1; i <= n; ++i) {
if (b) q.push({b, i});
}
for (int i = 1; i <= ans; ++i) {
for (int j = 1; j <= a; ++j) {
if (q.empty()) break;
pair <int, int> x = q.top();
q.pop();
jog[x.ss][i] = '-';
if (x.ff > 1) {
q.push ({x.ff - 1, x.ss});
}
}
if (q.empty()) break;
}
if (tr) {
for (int i = 1; i <= n; ++i) {
for (int j = m; j > 0; j--) {
if (jog[i][j] == '-') jog[i][j] = '+';
else jog[i][j] = '-';
}
}
int l1 = 1, r1 = m;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
jog1[i][j] = jog[l1][r1];
l1++;
}
l1 = 1;
r1--;
cout << endl;
}
if (tr) swap (n, m);
}
else {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
jog1[i][j] = jog[i][j];
}
}
}
//
// int row = 0, column = 0;
// for (int i = 1; i <= n; ++i) {
// int x = 0;
// for (int j = 1; j <= m; ++j) {
// if (jog1[i][j] == '+') x++;
// else x--;
// }
// if (x > 0) row++;
// }
// for (int i = 1; i <= m; i++) {
// int x = 0;
// for (int j = 1; j <= n; ++j) {
// if (jog1[j][i] == '-') x++;
// else x--;
// }
// if (x > 0) column++;
// }
// int tt = row + column;
//
cout << ans << endl;
// if (ans != tt) {
// cout << "men : " << row << " " << column << " " << tt << "\n";
// }
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cout << jog1[i][j];
}
cout << endl;
}
}
}
# | 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... |