#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<=m;j++)
{
minn = min(br[j],minn);
}
for(int j=1;j<=m;j++)
{
if(j > kol)
{
cout<<"+";
}
else if(i > red)
{
cout<<"-";
}
else if(i<=red && j<=kol)
{
if(sad_red <= 0)
{
cout<<"-";
}
else
{
if(br[j] == minn || (kol - j + 1) == treba)
{
treba--;
cout<<"+";
br[j]++;
}
else
{
cout<<"-";
}
}
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
in the table A+B is not equal to 28 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
5 ms |
376 KB |
in the table A+B is not equal to 28 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
1316 KB |
in the table A+B is not equal to 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
1272 KB |
in the table A+B is not equal to 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
5 ms |
376 KB |
in the table A+B is not equal to 28 |