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 endl '\n'
// #define double long double
// #define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;
int n, m;
int score(vector<vector<bool> > a) {
int col[m], row[n];
memset(col, 0, sizeof col);
memset(row, 0, sizeof row);
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
if (a[i][j]) {
row[i]++;
col[j]--;
}
else {
row[i]--;
col[j]++;
}
}
}
int ans = 0;
for (int i=0; i<m; i++) {
if (col[i] > 0) ans++;
}
for (int i=0; i<n; i++) {
if (row[i] > 0) ans++;
}
return ans;
}
void show(vector<vector<bool> > a) {
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
cout << (a[i][j] ? '+' : '-');
}
cout << endl;
}
}
void solve() {
cin >> n >> m;
int rfill = (m + 2) / 2;
int cfill = (n + 2) / 2;
vector<vector<bool> > grid1(n, vector<bool>(m, 0)); // allrows
vector<vector<bool> > grid2(n, vector<bool>(m, 1)); // allcols
// true is +, false is -
for (int i=0; i<n; i++) {
// all rows
if (i % 2 == 0) {
for (int j=0; j<rfill; j++) {
grid1[i][j] = true;
}
}
else {
int k = m - 1;
for (int j=0; j<rfill; j++, k--) {
grid1[i][k] = true;
}
}
}
for (int i=0; i<m; i++) {
// all cols
if (i % 2 == 0) {
for (int j=0; j<cfill; j++) {
grid2[j][i] = false;
}
}
else {
int k = n - 1;
for (int j=0; j<cfill; j++, k--) {
grid2[k][i] = false;
}
}
}
int asc = score(grid1);
int bsc = score(grid2);
if (asc > bsc) {
cout << asc << endl;
show(grid1);
}
else {
cout << bsc << endl;
show(grid2);
}
}
signed main() {
int t;
cin >> t;
while (t--) solve();
}
# | 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... |