This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int MAXN = (int)1e3 + 5;
const int INF = (int)1e9;
char s[MAXN][MAXN];
int cnt[MAXN];
int n, m;
pii ans;
int calc(int n, int m, vvi &ret) {
ans = mp(m, 0);
for (int i = 0; i < m; ++i) {
cnt[i] = n;
}
for (int step = 1, ptr = 0, col = m; step <= n; ++step) {
for (int i = 1; i <= m / 2 + 1; ++i) {
if (--cnt[ptr] <= n / 2) {
--col;
}
ptr = (ptr + 1) % m;
}
ans = max(ans, mp(step + col, step));
}
ret = vvi(n, vi(m, 0));
for (int step = 1, ptr = 0; step <= ans.se; ++step) {
for (int i = 1; i <= m / 2 + 1; ++i) {
ret[step - 1][ptr] = 1;
ptr = (ptr + 1) % m;
}
}
return ans.fi;
}
void solve() {
scanf("%d %d", &n, &m);
vvi Av, Bv;
int A, B;
A = calc(n, m, Av);
B = calc(m, n, Bv);
if (A >= B) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
s[i][j] = (Av[i][j] ? '+' : '-');
}
s[i][m] = '\0';
}
}
else {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
s[i][j] = (Bv[j][i] ? '-' : '+');
}
s[i][m] = '\0';
}
}
printf("%d\n", max(A, B));
for (int i = 0; i < n; ++i) {
printf("%s\n", s[i]);
}
}
int main() {
int tt;
scanf("%d", &tt);
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
stones.cpp: In function 'void solve()':
stones.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &tt);
~~~~~^~~~~~~~~~~
# | 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... |