#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define poc first
#define kraj second
#define maxn 1055005
using namespace std;
int n,m;
int treba_red;
int treba_kol;
bool moze(int red,int kol)
{
int sad_red = treba_red - (m - kol);
int sad_kol = treba_kol - (n - red);
int sad_n = red;
int sad_m = kol;
if(sad_red <= 0 || sad_kol <= 0)return true;
int uk_red = sad_red * sad_n;
int manji_kol = uk_red / sad_m;
int veci_kol = manji_kol + 1;
int br_veci = uk_red % sad_m;
if(br_veci > 0)
{
return sad_n - veci_kol >= sad_kol;
}
return sad_n - manji_kol >= sad_kol;
}
int br[1005];
void ispisi(int red,int kol)
{
cout<<red + kol<<"\n";
for(int i=1;i<=m;i++)br[i] = 0;
int sad_red = treba_red - (m - kol);
for(int i=1;i<=n;i++)
{
int treba = sad_red;
int minn = 10005;
for(int j=1;j<=kol;j++)
{
minn = min(br[j],minn);
}
for(int j=1;j<=m;j++)
{
if(j > kol)
{
cout<<"+";
}
else if(i > red)
{
cout<<"-";
}
else
{
if(treba <= 0)
{
cout<<"-";
}
else
{
if(br[j] == minn || (kol - j + 1) == treba)
{
treba--;
cout<<"+";
br[j]++;
}
else
{
cout<<"-";
}
}
}
}
cout<<"\n";
}
}
int main()
{
/*ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);*/
int t;
cin>>t;
while(t > 0)
{
t--;
cin>>n>>m;
treba_red = (m+2)/2;
treba_kol = (n+2)/2;
int maxx = 0;
int maxx_red = 0;
int maxx_kol = 0;
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
if(i + j > maxx && moze(i,j))
{
maxx = i + j;
maxx_red = i;
maxx_kol = j;
}
}
}
ispisi(maxx_red,maxx_kol);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
380 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
1408 KB |
Output is correct |
2 |
Correct |
40 ms |
1256 KB |
Output is correct |
3 |
Correct |
38 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
1272 KB |
Output is correct |
2 |
Correct |
38 ms |
1144 KB |
Output is correct |
3 |
Correct |
35 ms |
1124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
380 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
54 ms |
1408 KB |
Output is correct |
6 |
Correct |
40 ms |
1256 KB |
Output is correct |
7 |
Correct |
38 ms |
1272 KB |
Output is correct |
8 |
Correct |
46 ms |
1272 KB |
Output is correct |
9 |
Correct |
38 ms |
1144 KB |
Output is correct |
10 |
Correct |
35 ms |
1124 KB |
Output is correct |
11 |
Correct |
16 ms |
632 KB |
Output is correct |
12 |
Correct |
36 ms |
1136 KB |
Output is correct |
13 |
Correct |
38 ms |
1144 KB |
Output is correct |
14 |
Correct |
29 ms |
1016 KB |
Output is correct |
15 |
Correct |
45 ms |
1272 KB |
Output is correct |
16 |
Correct |
35 ms |
1080 KB |
Output is correct |
17 |
Correct |
16 ms |
632 KB |
Output is correct |