#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define N 1010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
using namespace std;
int t;
int n, m;
char v[N][N];
int main()
{
cin >> t;
while(t--) {
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int h = 1; h <= m; h++)
v[i][h] = (n > m ? '+' : '-');
if(n >= m) {
priority_queue <pii, vector <pii>, greater<pii>> Q;
for(int i = 1; i <= m; i++) Q.push({0, i});
int li = m/2 + 1;
int sz = n/2 - (n%2 == 0 ? 1 : 0);
for(int i = 1; i <= n; i++) {
vector <pii> A;
for(int h = 1; h <= li; h++) {
pii x = Q.top();
Q.pop();
if(x.ff == sz) break;
A.pb(x);
if(Q.empty()) break;
}
if(A.size() < li) break;
for(auto h: A) v[i][h.ss] = '+', Q.push({h.ff+1, h.ss});
}
}
else {
priority_queue <pii, vector <pii>, greater<pii>> Q;
for(int i = 1; i <= n; i++) Q.push({0, i});
int li = n/2 + 1;
int sz = m/2 - (m%2 == 0 ? 1 : 0);
for(int i = 1; i <= m; i++) {
vector <pii> A;
for(int h = 1; h <= li; h++) {
pii x = Q.top();
Q.pop();
if(x.ff == sz) break;
A.pb(x);
if(Q.empty()) break;
}
if(A.size() < li) break;
for(auto h: A) v[h.ss][i] = '-', Q.push({h.ff+1, h.ss});
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
int sum = 0;
for(int h = 1; h <= m; h++)
sum += (v[i][h] == '+' ? 1 : 0);
if(sum > m/2) ans++;
}
for(int i = 1; i <= m; i++) {
int sum = 0;
for(int h = 1; h <= n; h++)
sum += (v[h][i] == '-' ? 1 : 0);
if(sum > n/2) ans++;
}
cout << ans << "\n";
for(int i = 1; i <= n; i++) {
for(int h = 1; h <= m; h++)
cout << v[i][h];
cout << "\n";
}
}
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:56:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(A.size() < li) break;
~~~~~~~~~^~~~
stones.cpp:82:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(A.size() < li) break;
~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
252 KB |
Wrong answer in test 4 3: 4 < 5 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Wrong answer in test 3 45: 45 < 46 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
252 KB |
Wrong answer in test 4 3: 4 < 5 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
82 ms |
1436 KB |
Wrong answer in test 97 21: 97 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
1476 KB |
Output is correct |
2 |
Correct |
82 ms |
1872 KB |
Output is correct |
3 |
Correct |
71 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
252 KB |
Wrong answer in test 4 3: 4 < 5 |