Submission #500600

#TimeUsernameProblemLanguageResultExecution timeMemory
500600kusmetliqRed-blue table (IZhO19_stones)C++14
38 / 100
66 ms2032 KiB
#include<bits/stdc++.h> using namespace std; vector<char>anss[1002]; void sollve(int n,int m) { { for(int i=0;i<n;i++) { if(i<n/2) { for(int j=0;j<m/2+1;j++)anss[i].push_back('+'); for(int j=m/2+1;j<m;j++)anss[i].push_back('-'); } else if(i==n/2) { for(int j=0;j<m;j++)anss[i].push_back('-'); } else { for(int j=m/2+1;j<m;j++)anss[i].push_back('-'); for(int j=0;j<m/2+1;j++)anss[i].push_back('+'); } } } } void solve() { int n,m; cin>>n>>m; if(n==1){cout<<m<<endl;for(int i=0;i<m;i++)cout<<'-';cout<<endl;return;} if(m==1){cout<<n<<endl;for(int i=0;i<n;i++)cout<<'+'<<endl;return;} if(n%2==1 && m%2==1) { sollve(n,m); cout<<m-1+n-1<<endl; for(int i=0;i<n;i++) { for(int j=0;j<m;j++)cout<<anss[i][j]; cout<<endl; anss[i].clear(); } return; } char ans1[n][m],ans2[n][m]; int a1=n,a2=m; vector<int>v1(n,0),v2(m,0); for(int j=0;j<m;j++) { int cnt=0; for(int i=0;i<n;i++) { if(v1[i]<(m+1)/2-1)cnt++; } if(cnt>n/2) { a1++; int num=n/2+1; for(int i=0;i<n;i++) { if(v1[i]<m/2 && num!=0) { v1[i]++; num--; ans1[i][j]='-'; } else ans1[i][j]='+'; } } else for(int i=0;i<n;i++)ans1[i][j]='+'; } for(int i=0;i<n;i++) { int cnt=0; for(int j=0;j<m;j++) { if(v2[j]<(n+1)/2-1)cnt++; } if(cnt>m/2) { a2++; int num=m/2+1; for(int j=0;j<m;j++) { if(v2[j]<n/2 && num!=0) { v2[j]++; num--; ans2[i][j]='+'; } else ans2[i][j]='-'; } } else for(int j=0;j<m;j++)ans2[i][j]='-'; } cout<<max(a1,a2)<<endl; if(a2>a1) for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout<<ans2[i][j]; cout<<endl; } else for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout<<ans1[i][j]; cout<<endl; } } int main() { int t; cin>>t; while(t--)solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...