이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* #pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops") */
#include <bits/stdc++.h>
#define int long long
using namespace std;
int tc;
signed main () {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
if (n <= 4 && m <= 4) {
char a[n+1][m+1];
int k = n*m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '.';
}
}
int mx = -1, mxi = -1;
for (int mask = 0; mask <= (1 << k); mask++) {
bool ok = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mask & (1 << (i*m+j))) {
a[i+1][j+1] = '+';
} else {
a[i+1][j+1] = '-';
ok = 0;
}
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
int r = 0, b = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r > b) cnt++;
}
for (int j = 1; j <= m; j++) {
int r = 0, b = 0;
for (int i = 1; i <= n; i++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r > b) cnt++;
}
if (cnt > mx) {
mx = cnt;
mxi = mask;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '.';
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mxi & (1 << (i*m+j))) {
a[i+1][j+1] = '+';
} else {
a[i+1][j+1] = '-';
}
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
int r = 0, b = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r > b) cnt++;
}
for (int j = 1; j <= m; j++) {
int r = 0, b = 0;
for (int i = 1; i <= n; i++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r < b) cnt++;
}
cout << cnt << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << a[i][j];
}
cout << '\n';
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
stones.cpp: In function 'int main()':
stones.cpp:32:10: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
32 | bool ok = 1;
| ^~
# | 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... |