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 ll long long
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0), cin.tie(0);
#define fs first
#define ss second
#define print(a) \
for (auto x : a) \
cout << x << ' '; \
cout << endl;
#define printmp(a) \
for (auto x : a) \
cout << x.fs << ' ' << x.ss << endl;
void solve()
{
int n, m;
cin >> n >> m;
if (n >= m)
{
vector<vector<char>> a(n, vector<char> (m, '+'));
multiset<pair<int, int>> ml;
int l = m - (m + 2) / 2;
for (int i = 0; i < (n * l) / ((n + 2) / 2); i++)
ml.insert({0, i});
for(int i = 0; i < n; i ++){
for(int j = 0; j < l; j ++){
pair<int, int> x = *ml.begin();
ml.erase(ml.begin());
a[i][x.ss] = '-';
x.fs ++;
ml.insert(x);
}
}
int ans = 0;
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < m; j++)
{
if (a[i][j] == '+')
{
cnt++;
}
}
if (cnt > m - cnt)
{
ans++;
}
}
for (int i = 0; i < m; i++)
{
int cnt = 0;
for (int j = 0; j < n; j++)
{
if (a[j][i] == '-')
{
cnt++;
}
}
if (cnt > n - cnt)
{
ans++;
}
}
cout << ans << endl;
for(int i = 0; i < n; i ++){
for(int j = 0; j < m; j ++){
cout << a[i][j];
}
cout << endl;
}
}
else{
vector<vector<char>> a(n, vector<char>(m, '-'));
multiset<pair<int, int>> ml;
int l = n - (n + 2) / 2;
for (int i = 0; i < (m * l) / ((m + 2) / 2); i++)
ml.insert({0, i});
for (int i = 0; i < m; i++)
{
for (int j = 0; j < l; j++)
{
pair<int, int> x = *ml.begin();
ml.erase(ml.begin());
a[x.ss][i] = '+';
x.fs++;
ml.insert(x);
}
}
int ans = 0;
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < m; j++)
{
if (a[i][j] == '+')
{
cnt++;
}
}
if (cnt > m - cnt)
{
ans++;
}
}
for (int i = 0; i < m; i++)
{
int cnt = 0;
for (int j = 0; j < n; j++)
{
if (a[j][i] == '-')
{
cnt++;
}
}
if (cnt > n - cnt)
{
ans++;
}
}
cout << ans << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cout << a[i][j];
}
cout << endl;
}
}
}
signed main()
{
// fastio
int t = 1;
cin >> t;
while (t--)
{
solve();
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... |