QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#465223 | #8830. Breaking Bad | ucup-team1198# | WA | 1ms | 7916kb | C++20 | 3.7kb | 2024-07-06 19:03:54 | 2024-07-06 19:03:54 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const int MAXN = 1e3 + 100;
int a[MAXN][MAXN];
int shift(char mask, int d) {
return ((mask << d) & 31) | (mask >> (5 - d));
}
int add(int a, int b) {
return a + b >= 5 ? a + b - 5 : a + b;
}
int id[MAXN][MAXN];
char dp[MAXN * 12][64][64];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
int cnt = 0;
while (cnt < 4) {
int L = 2 * cnt;
bool found = false;
for (int i = L + 1; i < n && !found; ++i) {
for (int j = L + 1; j < n && !found; ++j) {
if (add(a[i][j], a[L][L]) != add(a[i][L], a[L][j])) {
found = true;
for (int t = 0; t < n; ++t) {
swap(a[i][t], a[L + 1][t]);
}
for (int t = 0; t < n; ++t) {
swap(a[t][j], a[t][L + 1]);
}
}
}
}
if (!found) break;
++cnt;
}
if (cnt >= 4) {
cout << "YYYYY\n";
return 0;
}
int cur_id = 0;
for (int i = n; i >= 2 * cnt; --i) {
for (int j = n; j >= 2 * cnt; --j) {
if (abs(i - j) <= 2 * cnt) {
id[i][j] = cur_id++;
}
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
if (abs(i - j) > 2 * cnt) {
id[i][j] = cur_id;
}
}
}
dp[id[n][n]][0][0] = 1;
for (int i = n; i >= 2 * cnt; --i) {
for (int j = n; j >= 2 * cnt; --j) {
/// cerr << i << " " << j << endl;
if (abs(i - j) > 2 * cnt) continue;
if (i == n && j == n) continue;
for (int maskr = 0; maskr < (1 << (2 * cnt)); ++maskr) {
for (int maskc = 0; maskc < (1 << (2 * cnt)); ++maskc) {
int I = id[i][j];
dp[I][maskr][maskc] = 0;
if (i != n && j != n) {
dp[I][maskr][maskc] |= shift(dp[id[i + 1][j + 1]][maskr][maskc], a[i][j]);
}
if (i != n) {
for (int c = 0; c < 2 * cnt; ++c) {
if (maskc & (1 << c)) {
dp[I][maskr][maskc] |= shift(dp[id[i + 1][j]][maskr][maskc ^ (1 << c)], a[i][c]);
}
}
}
if (j != n) {
for (int r = 0; r < 2 * cnt; ++r) {
if (maskr & (1 << r)) {
dp[I][maskr][maskc] |= shift(dp[id[i][j + 1]][maskr ^ (1 << r)][maskc], a[r][i]);
}
}
}
}
}
}
}
int I = id[2 * cnt][2 * cnt];
char ans = 0;
for (int maskr = 0; maskr < (1 << (2 * cnt)); ++maskr) {
for (int maskc = 0; maskc < (1 << (2 * cnt)); ++maskc) {
if (dp[I][maskr][maskc] == 0) continue;
vector<int> rows;
vector<int> cols;
for (int i = 0; i < 2 * cnt; ++i) {
if (!(maskr & (1 << i))) {
rows.push_back(i);
}
if (!(maskc & (1 << i))) {
cols.push_back(i);
}
}
do {
int sum = 0;
for (int i = 0; i < (int)cols.size(); ++i) {
sum = add(sum, a[rows[i]][cols[i]]);
}
ans |= shift(dp[I][maskr][maskc], sum);
} while (next_permutation(cols.begin(), cols.end()));
}
}
for (int i = 0; i < 5; ++i) {
if (ans & (1 << i)) {
cout << "Y";
} else {
cout << "N";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7644kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7916kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7876kb
input:
4 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7728kb
input:
4 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0
output:
YYYYY
result:
wrong answer 1st words differ - expected: 'YYYYN', found: 'YYYYY'