#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
14 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
1332 KB |
Output is correct |
2 |
Correct |
87 ms |
2040 KB |
Output is correct |
3 |
Correct |
88 ms |
3552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
1264 KB |
Output is correct |
2 |
Correct |
81 ms |
1620 KB |
Output is correct |
3 |
Correct |
77 ms |
1416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
4 |
Correct |
14 ms |
352 KB |
Output is correct |
5 |
Correct |
121 ms |
1332 KB |
Output is correct |
6 |
Correct |
87 ms |
2040 KB |
Output is correct |
7 |
Correct |
88 ms |
3552 KB |
Output is correct |
8 |
Correct |
95 ms |
1264 KB |
Output is correct |
9 |
Correct |
81 ms |
1620 KB |
Output is correct |
10 |
Correct |
77 ms |
1416 KB |
Output is correct |
11 |
Correct |
38 ms |
552 KB |
Output is correct |
12 |
Correct |
81 ms |
2704 KB |
Output is correct |
13 |
Correct |
86 ms |
2220 KB |
Output is correct |
14 |
Correct |
62 ms |
1652 KB |
Output is correct |
15 |
Correct |
93 ms |
2260 KB |
Output is correct |
16 |
Correct |
68 ms |
1736 KB |
Output is correct |
17 |
Correct |
34 ms |
1600 KB |
Output is correct |