#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
void solve(){
int n, m; cin >> n >> m;
int ans = 0;
vector<string> table;
bool swapped = false;
if (n > m) {
swap(n, m);
swapped = true;
}
block_of_code{
ans = m;
string filled(m, '-');
vector<int> cnt(m);
int les_n = (n-1) / 2;
for(int i = 0; i<n; ++i){
pair<int, int> what[m];
for(int j = 0; j < m; ++j) what[j] = {cnt[j], j};
sort(what, what + m);
string cur = filled;
int moore_m = m / 2 + 1;
for(int j = 0; j < moore_m; ++j){
cnt[what[j].second]++;
cur[what[j].second] = '+';
}
if (*max_element(ALL(cnt)) <= les_n){
table.push_back(cur);
ans++;
}
else table.push_back(filled);
}
}
cout << ans << "\n";
if (swapped){
vector<string> _table;
for(int j = 0; j < m; ++j) {
_table.push_back("");
for(int i = 0; i<n; ++i) {
if (table[i][j] == '+') _table.back().push_back('-');
else _table.back().push_back('+');
}
}
table = _table;
}
printArr(table, "\n");
}
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
int t; cin >> t;
while(t--) solve();
cerr << "Time elapsed: " << clock() - start << " ms\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
1500 KB |
Output is correct |
2 |
Correct |
20 ms |
2652 KB |
Output is correct |
3 |
Correct |
23 ms |
3096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1372 KB |
Output is correct |
2 |
Correct |
18 ms |
2392 KB |
Output is correct |
3 |
Correct |
20 ms |
1768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
20 ms |
1500 KB |
Output is correct |
6 |
Correct |
20 ms |
2652 KB |
Output is correct |
7 |
Correct |
23 ms |
3096 KB |
Output is correct |
8 |
Correct |
17 ms |
1372 KB |
Output is correct |
9 |
Correct |
18 ms |
2392 KB |
Output is correct |
10 |
Correct |
20 ms |
1768 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
20 ms |
2568 KB |
Output is correct |
13 |
Correct |
21 ms |
2128 KB |
Output is correct |
14 |
Correct |
14 ms |
1392 KB |
Output is correct |
15 |
Correct |
22 ms |
3460 KB |
Output is correct |
16 |
Correct |
17 ms |
2652 KB |
Output is correct |
17 |
Correct |
9 ms |
1628 KB |
Output is correct |