#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define y1 yy
#define tm hui_pizda
#define ft first
#define sd second
#define pb push_back
#define pf push_front
#define sz size()
#define cnt continue
#define m_p make_pair
#define fr(i, l, r) for(int i = l; i <= r; ++ i)
#define rf(i, r, l) for(int i = r; i >= l; -- i)
#pragma GCC optimize(-O3)
#pragma GCC optimize(Ofast)
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using _set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <pii> vpi;
typedef vector <pll> vpl;
mt19937_64 rnd(time(NULL));
const ll N = 1010;
const ll oo = 1e18 + 10;
const ll mod = 1000003;
ll a[N][N], ans[N][N], kx[N], ky[N], kans, n, m, T, w;
void calc(ll n, ll m, ll s){
bool ft = 1;
fr(i, 1, n)fr(j, 1, m){
if(a[i][j])kx[i] ++;
else ky[j] ++;
}
ll now = 0;
fr(i, 1, n)if(kx[i] * 2 > m)now ++;
fr(i, 1, m)if(ky[i] * 2 > n)now ++;
// cout << " " << now << endl;
// fr(i, 1, n){
// fr(j, 1, m)cout << a[i][j] << ' ';
// cout << endl;
// }
if(now > kans){
kans = now;
fr(i, 1, n)fr(j, 1, m)ans[i][j] = a[i][j];
}
fr(i, 1, n)kx[i] = 0;
fr(i, 1, m)ky[i] = 0;
fr(i, 1, n)fr(j, 1, m)a[i][j] = -1;
}
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> T;
while(T --){
cin >> n >> m;
fr(i, 1, n)fr(j, 1, m)a[i][j] = ans[i][j] = -1;
kans = -1;
if(n < m)w = 0;
else w = 1;
//0..2
fr(i, 0, 2){
//0..2
fr(j, 0, 2){
if(n < m){
fr(y, 1, j)fr(x, 1, n)a[x][y] = 1;
fr(x, 1, i)fr(y, 1, m)a[x][y] = 0;
} else {
fr(x, 1, i)fr(y, 1, m)a[x][y] = 0;
fr(y, 1, j)fr(x, 1, n)a[x][y] = 1;
}
fr(x, i + 1, n){
fr(y, j + 1, m){
if((x + y - i - j - 2) % 2 == 0)a[x][y] = w;
else a[x][y] = 1 - w;
}
}
calc(n, m, w);
}
}
fr(i, 1, n)fr(j, 1, m)a[i][j] = 0;
calc(n, m, w);
fr(i, 1, n)fr(j, 1, m)a[i][j] = 1;
calc(n, m, w);
cout << kans << endl;
fr(i, 1, n){
fr(j, 1, m){
if(ans[i][j] == 0)cout << '-';
else cout << '+';
}
cout << "\n";
}
cout << endl;
}
return 0;
}
/*
*/
Compilation message
stones.cpp:15:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
#pragma GCC optimize(-O3)
^
stones.cpp:16:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
#pragma GCC optimize(Ofast)
^~~~~
stones.cpp: In function 'void calc(ll, ll, ll)':
stones.cpp:6:12: warning: unused variable 'first' [-Wunused-variable]
#define ft first
^
stones.cpp:43:10: note: in expansion of macro 'ft'
bool ft = 1;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Wrong answer in test 4 4: 4 < 5 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Wrong answer in test 4 4: 4 < 5 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
2372 KB |
Output is correct |
2 |
Correct |
74 ms |
13164 KB |
Output is correct |
3 |
Correct |
70 ms |
16248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
2900 KB |
Wrong answer in test 4 4: 4 < 5 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Wrong answer in test 4 4: 4 < 5 |