QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#95836 | #5438. Half Mixed | reshke# | WA | 218ms | 3524kb | C++14 | 5.1kb | 2023-04-12 00:24:45 | 2023-04-12 00:24:47 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include "vector"
int len;
const int maxlen = 1e5 + 32;
using namespace std;
int f[10][10];
int preff[10][10];
int n = 3;
int m = 5;
int sm(int x1, int y1, int x2, int y2) {
return preff[x2][y2] + preff[x1 - 1][y1 - 1] - preff[x1 - 1][y2] - preff[x2][y1- 1];
}
int check() {
int cnt = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
for (int x = i; x < n; ++ x) {
for (int y = j; y < m; ++ y) {
if (sm(i + 1, j + 1, x + 1, y + 1) == 0 ||sm(i + 1, j + 1, x + 1, y + 1) == (x - i + 1) * (y - j + 1)) {
++cnt;
}
}
}
}
}
return 2 * cnt - n * (n + 1) / 2 * m * (m + 1) / 2;
}
void solved() {
int n, m;
cin >> n >> m;
bool rev = false;
if (n == 3 && m == 2) {
swap(n, m);
rev = true;
} else if(n == 4 && m == 3) {
swap(n, m);
rev = true;
} else if (n >= 4 && m % 4 == 0) {
swap(n, m);
rev = true;
} else if (m > 3 && m % 4 == 3) {
swap(n, m);
rev = true;
}
vector<vector<int>> solu(n, vector<int>(m, 0));
if (n == 2 && m == 3) {
cout << "Yes\n";
solu[0][2] = solu[1][0] = 1;
} else if (n == 3 && m == 4) {
cout << "Yes\n";
solu[0][1] = solu[1][1] = solu[2][1] = 1;
}else if (n == 4 && m == 4){
cout << "Yes\n";
solu[0][0] = solu[0][2] = 1;
solu[1][1] = 1;
}else if (n == 3 && m == 3){
cout << "Yes\n";
solu[2][0] = solu[2][2] = 1;
solu[0][2] = 1;
} else if (n % 4 == 0) {
cout << "Yes\n";
for (int i = 0; i < n; i += 4) {
for (int j = 0; j < m; ++j) {
solu[i][j] = 1;
}
solu[i + 1][0] = solu[i + 1][1] = solu[i + 1][2] = 1;
for (int j = 3; j < m; ++j) {
solu[i + 1][j] = 0;
}
solu[i + 2][0] = solu[i + 2][1] = solu[i + 2][2] = 1;
for (int j = 3; j < m; ++j) {
solu[i + 2][j] = 0;
}
for (int j = 0; j < m; ++j) {
solu[i + 3][j] = 0;
}
}
} else if (n % 4 == 3) {
cout << "Yes\n";
solu[0][0] = 0;
for (int j = 1; j < m; ++j) {
solu[0][j] = 1;
}
solu[1][0] = 0;
for (int j = 1; j < m; ++j) {
solu[1][j] = 1;
}
solu[2][0] = 0;
solu[2][1] = 0;
solu[2][2] = 0;
solu[2][3] = 1;
solu[2][4] = 0;
for (int j = 5; j < m; ++j) {
solu[2][j] = 0;
}
for (int i = 3; i < n; i += 4) {
for (int j = 0; j < m; ++j) {
solu[i][j] = 1;
}
solu[i + 1][0] = solu[i + 1][1] = solu[i + 1][2] = 1;
for (int j = 3; j < m; ++j) {
solu[i + 1][j] = 0;
}
solu[i + 2][0] = solu[i + 2][1] = solu[i + 2][2] = 1;
for (int j = 3; j < m; ++j) {
solu[i + 2][j] = 0;
}
for (int j = 0; j < m; ++j) {
solu[i + 3][j] = 0;
}
}
} else {
cout << "No\n";
return;
}
if (!rev) {
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < m; ++ j) {
cout << solu[i][j] << " ";
}
cout << "\n";
}
} else {
for (int j = 0; j < m; ++ j) {
for (int i = 0; i < n; ++ i) {
cout << solu[i][j] << " ";
}
cout << "\n";
}
}
return;
//
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < m; ++ j) {
cin >> f[i][j];
}
}
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
preff[i][j] = f[i - 1][j - 1] + preff[i - 1][j] + preff[i][j - 1] - preff[i - 1][j - 1];
}
}
cout << check() << "\n";
return;
for (uint64_t mask = 0; mask < (1ll << (n * m)); ++ mask) {
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < m; ++ j) {
f[i][j] = (mask & (1ll << (i * m + j))) ? 1 : 0;
}
}
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
preff[i][j] = f[i - 1][j - 1] + preff[i - 1][j] + preff[i][j - 1] - preff[i - 1][j - 1];
}
}
if (check()) {
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < m; ++ j) {
cout << f[i][j] << " ";
}
cout << "\n";
}
cout << "\n";
}
}
}
void solve () {
int t;
cin >> t;
while (t--) solved();
}
int main() {
std::cin.tie(0);
std::cout.tie(0);
std::ios_base::sync_with_stdio(false);
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3400kb
input:
2 2 3 1 1
output:
Yes 0 0 1 1 0 0 No
result:
ok OK, Accepted. (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 218ms
memory: 3524kb
input:
5382 1 1 1 2 2 1 1 3 2 2 3 1 1 4 2 3 3 2 4 1 1 5 2 4 3 3 4 2 5 1 1 6 2 5 3 4 4 3 5 2 6 1 1 7 2 6 3 5 4 4 5 3 6 2 7 1 1 8 2 7 3 6 4 5 5 4 6 3 7 2 8 1 1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 1 10 2 9 3 8 4 7 5 6 6 5 7 4 8 3 9 2 10 1 1 11 2 10 3 9 4 8 5 7 6 6 7 5 8 4 9 3 10 2 11 1 1 12 2 11 3 10 4 9 5 8 6 ...
output:
No No No No No Yes 0 0 0 No Yes 0 0 1 1 0 0 Yes 0 1 0 0 1 0 Yes 1 1 1 0 No No Yes 0 0 1 0 0 0 1 0 1 Yes 1 1 1 1 1 1 0 0 No No No Yes 0 1 0 0 0 1 0 0 0 1 0 0 Yes 0 0 0 1 1 1 0 0 0 0 0 0 No No Yes 0 0 0 1 1 1 0 No Yes 0 1 1 1 1 0 1 1 1 1 0 0 0 1 0 Yes 1 0 0 0 0 1 0 0 1 ...
result:
wrong answer Wrong Verdict (test case 4)