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>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 1e3 + 10;
int n, m;
int d[maxn];
bool check(int r, int c, int t)
{
int con = min((m - 1) / 2, c);
int nec = t * c;
///cout << r * con << " : " << nec << endl;
return r * con >= nec;
}
char table[maxn][maxn];
void solve()
{
cin >> n >> m;
//cout << check(3, 6, 1) << endl;
//exit(0);
int max_res = 0, mrow = -1, mcol = -1;
for (int x = 0; x <= n; x ++)
{
int nec = n / 2 + 1 - (n - x);
nec = max(nec, 0);
int lf = 0, rf = m + 1;
while(lf + 1 < rf)
{
int mf = (lf + rf) / 2;
if (check(x, mf, nec))
lf = mf;
else
rf = mf;
}
if (x + lf > max_res)
{
max_res = x + lf;
mrow = x;
mcol = lf;
}
}
cout << max_res << endl;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
table[i][j] = '+';
for (int i = mrow + 1; i <= n; i ++)
for (int j = 1; j <= mcol; j ++)
table[i][j] = '-';
int pv = 1;
int con = min((mrow - 1) / 2, mcol);
for (int i = 1; i <= mrow; i ++)
{
for (int step = 1; step <= con; step ++)
{
if (pv > mcol)
pv = 1;
table[i][pv] = '-';
pv ++;
}
}
for (int i = 1; i <= n; i ++, cout << endl)
for (int j = 1; j <= m; j ++)
cout << table[i][j];
}
int main()
{
speed();
int t;
cin >> t;
while(t --)
solve();
return 0;
}
# | 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... |