Submission #167720

#TimeUsernameProblemLanguageResultExecution timeMemory
167720beso123Red-blue table (IZhO19_stones)C++14
100 / 100
136 ms9208 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int t; bool sort21(pair<int,int> a,pair<int,int> b){ return a.first<b.first; } main(){ cin>>t; while(t--){ int n,m; cin>>n>>m; int M=(n/2)+1; int N=(m/2)+1; int a[n+1][m+1]; int b[max(n,m)+1]; for(int k=1;k<=max(n,m);k++) b[k]=0; for(int k=1;k<=n;k++){ for(int i=1;i<=m;i++) a[k][i]=0; } if(n>=m){ int ans=n; for(int i=1;i<=m;i++){ vector<pair<int,int> > v; for(int k=1;k<=n;k++){ v.push_back({b[k],k}); } sort(v.begin(),v.end(),sort21); if(v[M-1].first<m-N){ ans++; for(int k=0;k<M;k++){ a[v[k].second][i]=1; b[v[k].second]++; } } else break; } cout<<ans<<endl; for(int k=1;k<=n;k++){ for(int i=1;i<=m;i++) if(a[k][i]) cout<<'-'; else cout<<'+'; cout<<endl; } } else{ int ans=m; for(int i=1;i<=n;i++){ vector<pair<int,int> > v; for(int k=1;k<=m;k++){ v.push_back({b[k],k}); } sort(v.begin(),v.end(),sort21); if(v[N-1].first<n-M){ ans++; for(int k=0;k<N;k++){ a[i][v[k].second]=1; b[v[k].second]++; } } else break; } cout<<ans<<endl; for(int k=1;k<=n;k++){ for(int i=1;i<=m;i++) if(a[k][i]) cout<<'+'; else cout<<'-'; cout<<endl; } } } return 0; }

Compilation message (stderr)

stones.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#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...