#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n,m,t;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>t;
while(t--){
cin>>n>>m;
if(n==1){
cout<<m<<endl;
for(int j=0;j<m;j++){
cout<<"-";
}
cout<<endl;
}
else if(m==1){
cout<<n<<endl;
for(int j=0;j<n;j++){
cout<<"+"<<endl;
}
cout<<endl;
}
else if(n==2){
cout<<m<<endl;
for(int i=0;i<m;i++){
cout<<"-";
}
cout<<endl;
for(int i=0;i<m;i++){
cout<<"-";
}
cout<<endl;
}
else if(m==2){
cout<<n<<endl;
for(int i=0;i<n;i++){
cout<<"++"<<endl;
}
}
else if(n==3){
cout<<(m+1)<<endl;
for(int i=0;i<m;i++){
cout<<"-";
}
cout<<endl;
for(int i=0;i<m;i++){
cout<<"+";
}
cout<<endl;
for(int i=0;i<m;i++){
cout<<"-";
}
cout<<endl;
}
else if(m==3){
cout<<(n+1)<<endl;
for(int i=0;i<n;i++){
cout<<"+-+"<<endl;
}
}
else if(n==4){
cout<<m+1<<endl;
for(int j=0;j<3;j++){
for(int i=0;i<m;i++){
cout<<"-";
}
cout<<endl;
}
for(int i=0;i<m;i++){
cout<<"+";
}
cout<<endl;
}
else if(m==4){
cout<<n+1<<endl;
for(int i=0;i<n;i++){
cout<<"+++-"<<endl;
}
}
/*else if(m%2==1 and n%2==1){
if(m+3+(n-5)/2>n+3+(m-5)/2){
cout<<(m+3+(n-5)/2)<<endl;
int it[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
it[i][j]=0;
}
}
for(int i=0;i<(m+2)/2;i++){
it[0][i]=1;
}
for(int i=m-(m+2)/2;i<m;i++){
it[1][i]=1;
}
for(int j=0;j<m;j++){
if(it[0][j]!=1 or it[1][j]!=1){
it[2][j]=1;
}
}
for(int i=5;i<n;i+=2){
for(int j=0;j<m;j++){
it[i][j]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]==1){
cout<<"+";
}
else{
cout<<"-";
}
}
cout<<endl;
}
}
else{
cout<<(n+3+(m-5)/2)<<endl;
int it[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
it[i][j]=0;
}
}
for(int i=0;i<(n+2)/2;i++){
it[i][0]=1;
}
for(int i=n-(n+2)/2;i<n;i++){
it[i][1]=1;
}
for(int j=0;j<n;j++){
if(it[j][0]!=1 or it[j][1]!=1){
it[j][2]=1;
}
}
for(int j=5;j<m;j+=2){
for(int i=0;i<n;i++){
it[i][j]=1;
// cout<<i<<","<<j<<endl;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]==1){
cout<<"-";
}
else{
cout<<"+";
}
}
cout<<endl;
}
}
}*/
else if(n==5){
cout<<(m+3+(n-5)/2)<<endl;
int it[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
it[i][j]=0;
}
}
for(int i=0;i<(m+2)/2;i++){
it[0][i]=1;
}
for(int i=m-(m+2)/2;i<m;i++){
it[1][i]=1;
}
for(int j=0;j<m;j++){
if(it[0][j]!=1 or it[1][j]!=1){
it[2][j]=1;
}
}
for(int i=5;i<n;i+=2){
for(int j=0;j<m;j++){
it[i][j]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]==1){
cout<<"+";
}
else{
cout<<"-";
}
}
cout<<endl;
}
}
else if(m==5){
cout<<(n+3)<<endl;
int it[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
it[i][j]=0;
}
}
for(int i=0;i<(n+2)/2;i++){
it[i][0]=1;
}
for(int i=n-(n+2)/2;i<n;i++){
it[i][1]=1;
}
for(int j=0;j<n;j++){
if(it[j][0]!=1 or it[j][1]!=1){
it[j][2]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]==1){
cout<<"-";
}
else{
cout<<"+";
}
}
cout<<endl;
}
}
else if(m==n){
if(m==6){
cout<<9<<endl;
cout<<"++++--"<<endl;
cout<<"--++++"<<endl;
cout<<"++--++"<<endl;
cout<<"------"<<endl;
cout<<"------"<<endl;
cout<<"------"<<endl;
continue;
}
int it[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
it[i][j]=0;
}
}
if(m%2==1 and n%2==1){
cout<<(4*(m/2))<<endl;
for(int i=0;i<(m+1)/2;i++){
for(int j=0;j<(n)/2;j++){
it[j][i]=1;
}
}
for(int i=0;i<(m+1)/2;i++){
for(int j=0;j<(n)/2;j++){
it[n-j-1][m-i-1]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]==1){
cout<<"+";
}
else{
cout<<"-";
}
}
cout<<endl;
}
}
else{
cout<<(4*(n/2-1))<<endl;
for(int i=0;i<(m+2)/2;i++){
for(int j=0;j<(n-1)/2;j++){
it[j][i]=1;
}
}
for(int i=0;i<(m+2)/2;i++){
for(int j=0;j<(n-1)/2;j++){
it[n-j-1][m-i-1]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]==1){
cout<<"+";
}
else{
cout<<"-";
}
}
cout<<endl;
}
}
}
else{
int k=(n+2)/2;
int l=(m+2)/2;
int ma=-1;
pair<int,int> aa={-1,-1};
int bb=m;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i*l+j*k<=n*m){
int le2=m-j;
int st=1;
if(l>le2){
if((l-le2)*i>(n-k)*(j)){
st=0;
}
}
if(st){
if(i+j>ma){
ma=i+j;
aa={i,j};
}
}
}
}
/*if(i+bb>=ma){
ma=i+bb;
aa={i,bb};
}*/
}
if(aa.b<0){
while(true){
continue;
}
}
int it[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
it[i][j]=0;
}
}
int le=m-aa.b;
/*if(ma==34){
return 0;
}*/
//cout<<ma<<endl;
deque<int> freq[1001];
int ind=0;
for(int i=0;i<1001;i++){
freq[i].clear();
}
for(int i=le;i<m;i++){
freq[0].pb(i);
}
//(m-le)
//cout<<aa.a<<","<<aa.b<<endl;
int vis[1001];
for(int i=0;i<1001;i++){
vis[i]=0;
}
int cot[1001];
for(int i=0;i<1001;i++){
cot[i]=0;
}
for(int i=0;i<aa.a;i++){
vector<int> kk;
for(int j=0;j<l;j++){
if(j<le){
it[i][j]=1;
continue;
}
if(freq[ind].size()==0){
ind+=1;
}
/* if(ind>=(m-1)/2){
while(true){
continue;
}
}*/
it[i][freq[ind].back()]=1;
// cout<<i<<":"<<freq[ind].back()<<endl;
int xx=freq[ind].back();
kk.pb(xx);
vis[xx]=1;
cot[xx]+=1;
/* if(ind>=(n-1)/2){
while(true){
continue;
}
}*/
freq[ind+1].push_front(xx);
freq[ind].pop_back();
}
for(auto j:kk){
vis[j]=0;
}
}
int coo=0;
for(int i=0;i<m;i++){
int co=0;
for(int j=0;j<n;j++){
if(it[j][i]==0){
co+=1;
}
}
if(co>=k){
coo+=1;
}
}
cout<<ma<<endl;
// cout<<coo+aa.a<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]==1){
cout<<"+";
}
else{
cout<<"-";
}
}
cout<<endl;
}
}
/*int it[n][m];
if(n>m){
int l=0;
for(int i=0;i<n;i++){
for(int j=l;j<l+(m+2)/2;j++){
it[i][j%m]=1;
}
l=l+(m+2)/2;
l%=m;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(it[i][j]){
cout<<"+";
}
else{
cout<<"-";
}
}
cout<<endl;
}
}
else{
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i%2==0){
cout<<"-";
}
else{
cout<<"+";
}
}
cout<<endl;
}
}*/
}
return 0;
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:302:8: warning: unused variable 'bb' [-Wunused-variable]
int bb=m;
^~
stones.cpp:352:8: warning: variable 'vis' set but not used [-Wunused-but-set-variable]
int vis[1001];
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
13 ms |
384 KB |
Output is correct |
4 |
Correct |
23 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
2056 KB |
Output is correct |
2 |
Correct |
41 ms |
4484 KB |
Output is correct |
3 |
Correct |
40 ms |
4856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
1400 KB |
Output is correct |
2 |
Correct |
33 ms |
3192 KB |
Output is correct |
3 |
Correct |
29 ms |
2432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
13 ms |
384 KB |
Output is correct |
4 |
Correct |
23 ms |
384 KB |
Output is correct |
5 |
Correct |
109 ms |
2056 KB |
Output is correct |
6 |
Correct |
41 ms |
4484 KB |
Output is correct |
7 |
Correct |
40 ms |
4856 KB |
Output is correct |
8 |
Correct |
50 ms |
1400 KB |
Output is correct |
9 |
Correct |
33 ms |
3192 KB |
Output is correct |
10 |
Correct |
29 ms |
2432 KB |
Output is correct |
11 |
Correct |
82 ms |
1324 KB |
Output is correct |
12 |
Correct |
39 ms |
3584 KB |
Output is correct |
13 |
Correct |
42 ms |
3076 KB |
Output is correct |
14 |
Correct |
34 ms |
2368 KB |
Output is correct |
15 |
Correct |
34 ms |
5248 KB |
Output is correct |
16 |
Correct |
33 ms |
4728 KB |
Output is correct |
17 |
Correct |
18 ms |
2688 KB |
Output is correct |