# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
using namespace std;
const int N = 1e3 + 7;
const int mod = 1e9 + 7;
char a[N][N], cnt[N];
void solve() {
int n, m;
cin >> n >> m;
int ans = m;
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= m; j++ ) {
a[i][j] = '-';
cnt[j] = 0;
}
}
int ind = 0;
for ( int i = 1; i <= n; i++ ) {
int nd = (m + 1) / 2;
for ( int j = 1; j <= m; j++ ) {
if ( ((n - cnt[j]) < (n + 1) / 2) && nd ) {
nd--;
cnt[j]++;
a[i][j] = '+';
}
}
set < pair < int, int > > st;
for ( int j = 1; j <= m; j++ ) {
if ( a[i][j] == '-' ) {
st.insert( { cnt[j], j } );
}
}
while ( nd ) {
int j = st.begin()->se;
st.erase( st.begin() );
a[i][j] = '+';
nd--;
cnt[j]++;
}
int c = i;
for ( int j = 1; j <= m; j++ ) {
if ( (n - cnt[j]) >= (n + 1) / 2 ) {
c++;
}
}
if ( c > ans ) {
ind = i;
ans = c;
}
}
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= m; j++ ) {
a[i][j] = '-';
cnt[j] = 0;
}
}
for ( int i = 1; i <= ind; i++ ) {
int nd = (m + 1) / 2;
for ( int j = 1; j <= m; j++ ) {
if ( ((n - cnt[j]) < (n + 1) / 2) && nd ) {
nd--;
cnt[j]++;
a[i][j] = '+';
}
}
set < pair < int, int > > st;
for ( int j = 1; j <= m; j++ ) {
if ( a[i][j] == '-' ) {
st.insert( { cnt[j], j } );
}
}
while ( nd ) {
int j = st.begin()->se;
st.erase( st.begin() );
a[i][j] = '+';
nd--;
cnt[j]++;
}
int c = i;
for ( int j = 1; j <= m; j++ ) {
if ( (n - cnt[j]) >= (n + 1) / 2 ) {
c++;
}
}
if ( c > ans ) {
ind = i;
ans = c;
}
}
cout << ans << '\n';
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= m; j++ ) {
cout << a[i][j];
}
cout << '\n';
}
}
int32_t main() {
speed;
int T = 1;
cin >> T;
while ( T-- ) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
364 KB |
in the table A+B is not equal to 2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
201 ms |
1436 KB |
Wrong answer in test 97 21: 112 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
213 ms |
1576 KB |
in the table A+B is not equal to 48 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 2 |