QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#95835 | #5438. Half Mixed | reshke# | WA | 2ms | 3416kb | C++14 | 5.1kb | 2023-04-12 00:24:08 | 2023-04-12 00:24:12 |
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: 0
Wrong Answer
time: 2ms
memory: 3416kb
input:
2 2 3 1 1
output:
Yes 0 0 1 1 0 0 NO
result:
wrong answer Token "NO" doesn't correspond to pattern "Yes|No" (test case 2)