#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int mat[N][N]; // +1 + -1 -
void print(int n, int m, bool flip){
if(flip)
swap(n, m);
for(int i=1; i<=n; i++){
for(int j=1; j<=m;j++){
char out;
if(flip){
if(mat[j][i] * (-1) == 1)
out = '+';
else
out = '-';
}
else{
if(mat[i][j] == 1)
out = '+';
else
out = '-';
}
cout<<out;
}
cout<<"\n";
}
}
inline int mid(int n){
int m = n/2;
while(m <= n- m)
m++;
return m;
}
int extra[N];
void solve(){
int n, m;
bool flip = false;
cin>>n>>m;
if(n > m){
swap(n, m);
flip = true;
}
for(int i=1;i<=n;i++){
for(int j =1; j<=m;j++)
mat[i][j] = -1;
}
for(int i=1;i<=m;i++){
extra[i] = n - mid(n);
}
int ans = m;
for(int i=1; i<=n;i++){
priority_queue<pair<int, int>> pq;
for(int j = 1; j<=m;j++){
if(extra[j]){
pq.push({extra[j], j});
}
}
int k = mid(m);
if(pq.size() <k )
break;
while(k--){
auto x = pq.top();
pq.pop();
mat[i][x.second] = 1;
extra[x.second]--;
}
ans++;
}
cout<<ans<<"\n";
print(n, m , flip);
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int nrt;
cin>>nrt;
for(int i=1;i<=nrt;i++){
solve();
}
return 0;
}
Compilation message
stones.cpp: In function 'void solve()':
stones.cpp:59:18: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
59 | if(pq.size() <k )
| ~~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
1784 KB |
Output is correct |
2 |
Correct |
77 ms |
4204 KB |
Output is correct |
3 |
Correct |
69 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
2028 KB |
Output is correct |
2 |
Correct |
66 ms |
4076 KB |
Output is correct |
3 |
Correct |
63 ms |
3436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
5 |
Correct |
73 ms |
1784 KB |
Output is correct |
6 |
Correct |
77 ms |
4204 KB |
Output is correct |
7 |
Correct |
69 ms |
4204 KB |
Output is correct |
8 |
Correct |
81 ms |
2028 KB |
Output is correct |
9 |
Correct |
66 ms |
4076 KB |
Output is correct |
10 |
Correct |
63 ms |
3436 KB |
Output is correct |
11 |
Correct |
15 ms |
768 KB |
Output is correct |
12 |
Correct |
63 ms |
3308 KB |
Output is correct |
13 |
Correct |
68 ms |
3456 KB |
Output is correct |
14 |
Correct |
49 ms |
2540 KB |
Output is correct |
15 |
Correct |
81 ms |
5356 KB |
Output is correct |
16 |
Correct |
60 ms |
4204 KB |
Output is correct |
17 |
Correct |
27 ms |
2540 KB |
Output is correct |