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;
int calc(vector<string> &v, int n, int m){
int cnt = 0;
for(int i = 0; i < n; i++){
int a = 0, b= 0 ;
for(int j = 0; j < m; j++){
if(v[i][j] == '+') a++;
else b++;
}
cnt += (a > b);
}
for(int j = 0; j < m; j++){
int a = 0, b = 0;
for(int i = 0; i < n; i++){
if(v[i][j] == '-') a++;
else b++;
}
cnt += (a > b);
}
return cnt;
}
void printVec(vector<string> &v, int n, int m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << v[i][j];
}
cout << endl;
}
}
vector<string> rev(vector<string> v, int n, int m){
vector<string> a(m);
for(int i = 0; i < n; ++i){
for(int j = m - 1; j >= 0; --j){
if(v[i][j] == '+') a[m - j - 1].push_back('-');
else a[m - j - 1].push_back('+');
}
}
return a;
}
void solve(){
int n, m; cin >> n >> m;
set<pair<int, int>> st;
bool r = 0;
if(n > m){
swap(n, m);
r = 1;
}
string s(m, '-');
vector<string> v(n, s);
for(int i = 0; i < m; i++) st.insert({0, i});
int tuylatreli = (n + 1) / 2 - 1;
for(int i = 0; i < n; i++){
int petq = m / 2 + 1;
while(petq--){
auto it = st.begin();
pair<int, int> p = *it;
if(p.first == tuylatreli) break;
v[i][p.second] = '+';
st.erase(p);
st.insert({p.first + 1, p.second});
}
}
if(r) v = rev(v, n, m), swap(n, m);
cout << calc(v, n, m) << endl;
printVec(v, n, m);
}
int main(){
int t; cin >> t; while(t--)
solve();
}
# | 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... |