# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167681 | beso123 | Red-blue table (IZhO19_stones) | C++14 | 134 ms | 1508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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<=n;k++){
b[k]=0;
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[N-1].first==N-2)
break;
ans++;
for(int k=0;k<N;k++){
a[v[k].second][i]=1;
b[v[k].second]++;
}
}
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[M-1].first==M-2)
break;
ans++;
for(int k=0;k<M;k++){
a[i][v[k].second]=1;
b[v[k].second]++;
}
}
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |