# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
898063 | Litusiano | Red-blue table (IZhO19_stones) | C++14 | 0 ms | 0 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>
using namespace std;
#define int long long
#define f first
#define s second
#define endl '\n'
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin>>t;
while(t--){
int BOT = n/2;
int BOT1 = m/2;
int REM = n - BOT -1;
int REM1 = m-BOT1 - 1;
int a = n;
a+= n*REM1/(BOT+1);
int b = m ;
b+= m*REM/(BOT1+1);
if(a >= b){
cerr<<"HERE!"<<endl;
int x = a-n;
vector<vector<int>> v(n, vector<int>(m,1)); // all red
vector<int> need(x,BOT+1);
for(int i = 0; i<n; i++){
int hv = REM1;
for(int j = 0; j<REM1; j++){
int mn = -INT_MAX; int idx = -1;
for(int k = 0; k<need.size(); k++){
if(need[k] > mn) mn = need[k], idx = k;
}
hv--;
need[idx]--;
// cerr<<i<<" "<<idx<<endl;
v[i][idx] = 0;
}
}
cout<<a<<endl;
for(auto x : v){
for(auto y : x){
if(y) cout<<"+";
else cout<<"-";
}
cout<<endl;
}
}
else{
cerr<<"HERE1!"<<endl;
int x = b-m;
// He activat columnes, ara haig dactivar files.
vector<vector<int>> v(n, vector<int>(m,0)); // all red
vector<int> need(x,BOT1+1);
for(int i = 0; i<m; i++){
int hv = REM;
for(int j = 0; j<REM; j++){
int mn = -INT_MAX; int idx = -1;
for(int k = 0; k<need.size(); k++){
if(need[k] > mn) mn = need[k], idx = k;
}
hv--;
need[idx]--;
v[idx][i] = 1;
}
}
cout<<b<<endl;
for(auto x : v){
for(auto y : x){
if(y) cout<<"+";
else cout<<"-";
}
cout<<endl;
}
}
}
}
/*
1 3 7 9 10
10 + 24
9 + 11
7 + 4
1 + 3
*/