This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e3 + 50;
bool jako_dobar(int r, int s, int x, int y){
x = max(x, 0), y = max(y, 0);
if(x > s || y > r) return 0;
if(!s || !r) return 1;
return (r * x + s - 1) / s <= r - y;
}
bool dobar(int n, int m, int a, int b){
return jako_dobar(a, b, (m + 2) / 2 - (m - b), (n + 2) / 2 - (n - a));
}
int A[N][N];
void construct(int n, int m, int a, int b){
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++)
A[i][j] = (j >= b);
}
int r = a, s = b, x = (m + 2) / 2 - (m - b);
int cur = 0;
for(int i = 0;i < r;i++){
for(int j = 0;j < x;j++){
A[i][cur] = 1;
cur = (cur + 1) % s;
}
}
printf("%d\n", a + b);
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++)
printf(A[i][j] ? "+" : "-");
printf("\n");
}
}
int main(){
int T; scanf("%d", &T);
for(;T--;){
int n, m; scanf("%d%d", &n, &m);
int A = 0, B = 0;
for(int a = 0;a <= n;a++)
for(int b = 0;b <= m;b++)
if(a + b > A + B && dobar(n, m, a, b))
A = a, B = b;
construct(n, m, A, B);
}
return 0;
}
Compilation message (stderr)
stones.cpp: In function 'int main()':
stones.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
43 | int T; scanf("%d", &T);
| ~~~~~^~~~~~~~~~
stones.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
45 | int n, m; scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |