이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, X = 10;
mt19937 rng(time(nullptr));
int t, n, m, ans, idx, r[N], c[N];
vector<string> a[X];
int f(int x) {
for (int i = 0; i < n; i++) {
r[i] = 0;
}
for (int i = 0; i < m; i++) {
c[i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[x][i][j] == '+') r[i]++;
else c[j]++;
}
}
int y = 0;
for (int i = 0; i < n; i++) {
y += (r[i] > m/2);
}
for (int i = 0; i < m; i++) {
y += (c[i] > n/2);
}
return y;
}
/*
void debug(int x) {
cout << f(x) << "\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << a[x][i][j];
}
cout << "\n";
}
cout << "\n";
}
*/
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> t;
while (t--) {
cin >> n >> m;
ans = 0;
// mis 4 construcciones
a[0].clear();
a[0].resize(n, string(m, '-'));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j <= m/2) a[0][i][j] = '+';
}
}
int y = f(0);
if (y > ans) {
ans = y;
idx = 0;
}
// ---
a[1].clear();
a[1].resize(n, string(m, '+'));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i <= n/2) a[1][i][j] = '-';
}
}
y = f(1);
if (y > ans) {
ans = y;
idx = 1;
}
// ---
a[2].clear();
a[2].resize(n, string(m, '+'));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i <= n/2 && j < m/2) || (i >= n/2 && j > m/2)) a[2][i][j] = '-';
}
}
y = f(2);
if (y > ans) {
ans = y;
idx = 2;
}
// ---
a[3].clear();
a[3].resize(n, string(m, '-'));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i < n/2 && j <= m/2) || (i > n/2 && j >= m/2)) a[3][i][j] = '+';
}
}
y = f(3);
if (y > ans) {
ans = y;
idx = 3;
}
// X construcciones random
for (int x = 0; x < X; x++) {
a[x+4].clear();
a[x+4].resize(n, string(m, '+'));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (rng() % 2) a[x+4][i][j] = '-';
}
}
int y = f(x+4);
if (y > ans) {
ans = y;
idx = x+4;
}
}
cout << ans << "\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << a[idx][i][j];
}
cout << "\n";
}
}
}
# | 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... |