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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
// 3 3
// -++
// +-+
// -++
// wlog N > M
// every row will have N/2+1 red stones
// then make rows
int main(){
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
int ans = 0;
char mat[n][m];
if(n >= m){
int minus[m];
memset(minus, 0, sizeof minus);
for(int i = 0; i < n; i++){
int need = m/2 + 1;
for(int j = 0; j < m; j++){
if(minus[j] < n/2+1 && (m-j-1) >= need){
minus[j]++;
mat[i][j] = '-';
}
else{
mat[i][j] = '+';
need--;
}
}
ans++;
}
for(int i = 0; i < m; i++){
if(minus[i] >= n/2+1) ans++;
}
cout<<ans<<"\n";
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cout<<mat[i][j];
cout<<endl;
}
}
else{
int plus[n];
memset(plus, 0, sizeof plus);
for(int j = 0; j < m; j++){
int need = n/2 + 1;
for(int i = 0; i < n; i++){
if(plus[i] < m/2+1 && (n - i - 1) >= need){
mat[i][j] = '+';
plus[i]++;
}
else{
mat[i][j] = '-';
need--;
}
}
ans++;
}
for(int i = 0; i < n; i++)
if(plus[i] >= m / 2 + 1) ans++;
cout<<ans<<"\n";
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cout<<mat[i][j];
cout<<endl;
}
}
}
return 0;
}
# | 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... |