#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define endl "\n"
int n, m;
int calc(vector<vector<int>>& a) {
int cur = 0;
for (int i = 0; i < n; ++i) {
int x = 0;
for (int j = 0; j < m; ++j) {
if (a[i][j]) x++;
else x--;
}
if (x > 0) cur++;
}
for (int j = 0; j < m; ++j) {
int x = 0;
for (int i = 0; i < n; ++i) {
if (a[i][j]) x++;
else x--;
}
if (x < 0) cur++;
}
return cur;
}
int main() {
int tt;
cin >> tt;
while (tt--) {
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
int max1 = 0;
for (int i = -1; i < n; ++i) {
for (int j = -1; j < m; ++j) {
a = vector<vector<int>>(n, vector<int>(m));
for (int k = 0; k <= i; ++k) {
for (int z = 0; z <= j; ++z) {
a[k][z] = 1;
}
}
int cur = calc(a);
if (cur > max1) {
max1 = cur;
}
}
}
cout << max1 << endl;
bool ok = false;
for (int i = -1; i < n; ++i) {
if (ok) continue;
for (int j = -1; j < m; ++j) {
a = vector<vector<int>>(n, vector<int>(m));
for (int k = 0; k <= i; ++k) {
for (int z = 0; z <= j; ++z) {
a[k][z] = 1;
}
}
int cur = calc(a);
if (cur == max1 && !ok) {
//max1 = cur;
for (auto elem : a) {
for (auto u : elem) {
if (u) cout << "+";
else cout << "-";
}
cout << endl;
}
cout << endl;
ok = true;
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
48 ms |
364 KB |
Output is correct |
4 |
Incorrect |
117 ms |
364 KB |
Wrong answer in test 5 29: 31 < 32 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2074 ms |
784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2074 ms |
748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
48 ms |
364 KB |
Output is correct |
4 |
Incorrect |
117 ms |
364 KB |
Wrong answer in test 5 29: 31 < 32 |