이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC
#define fi first
#define se second
#define int long long int
#define dl double long
using namespace std;
const int N = 1e6 + 7;
const int INF = 1e10 + 7;
const int mod = 998244353;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve1()
{
int n, m;
cin >> n >> m;
if(n < 3 && n == min(n, m)){
cout << m << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << '-';
}
cout << endl;
}
return;
}
if(m < 3 && m == min(n, m)){
cout << n << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << '+';
}
cout << endl;
}
return;
}
if(m >= n && (m < 5 || n < 5)){
int x = m / 2 + 1;
int y = n / 2 - 1;
if(n % 2 == 1)
y++;
bool f = true;
if(x * 2 - m > y)
f = false;
cout << y * 2 + (m - x) * 2 + (- y + x * 2 - m) * !f << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if((j < x && i < y) || (j + 1 > m - x && i + 1 > n - y && f)){
cout << '+';
}else{
cout << '-';
}
}
cout << endl;
}
return;
}else if(n > m && (m < 5 | n < 5)){
int x = m / 2 - 1;
if(m % 2 == 1)
x++;
int y = n / 2 + 1;
bool f = true;
if(y * 2 - n > x)
f = false;
cout << x * 2 + (n - y) * 2 + (- x + y * 2 - n) * !f << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if((j < x && i < y) || (j + 1 > m - x && i + 1 > n - y && f)){
cout << '-';
}else{
cout << '+';
}
}
cout << endl;
}
return;
}
if(m >= n){
cout << m + (n + 1) / 2 << endl;
for(int i = 0; i < (n + 1) / 2; i++){
for(int j = 0; j < m; j++){
if((i + j) % ((n + 1) / 2) == 0){
cout << '-';
}else{
cout << '+';
}
}
cout << endl;
}
for(int i = (n + 1) / 2; i < n; i++){
for(int j = 0; j < m; j++){
cout << '-';
}
cout << endl;
}
}else{
cout << n + (m + 1) / 2 << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < (m + 1) / 2; j++){
if((i + j) % ((m + 1) / 2) == 0){
cout << '+';
}else{
cout << '-';
}
}
cout << endl;
}
for(int i = 0; i < n; i++){
for(int j = (m + 1) / 2; j < m; j++){
cout << '+';
}
cout << endl;
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0); srand(time(0));
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
//freopen( "cupboard.in" , "r" , stdin );
//freopen( "cupboard.out" , "w" , stdout );
int cghf = 1;cin >> cghf;
while( cghf-- ){
solve1();
}
}
컴파일 시 표준 에러 (stderr) 메시지
stones.cpp: In function 'void solve1()':
stones.cpp:63:26: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
63 | }else if(n > m && (m < 5 | n < 5)){
| ~~^~~
# | 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... |