QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#583794 | #8830. Breaking Bad | ucup-team3519 | WA | 33ms | 7052kb | C++14 | 4.7kb | 2024-09-22 22:28:20 | 2024-09-22 22:28:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define cin std::cin
#define cout std::cout
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
//const int MN = 2e5 + 20;
const int INF = 2e9 + 1000;//INF
const LL INFLL = 8e18 + 1000;//INF long long
mt19937 mrand(chrono::steady_clock().now().time_since_epoch().count());
//模板区域~~~~~~~
const int mod = 5;
int MOD(int x) {
if(x < 0) return x + mod;
if(x >= mod) return x - mod;
return x;
}
//模板结束~~~~~~~
void solve() {
int n; cin >> n;
V<V<int>> a(n + 1, V<int>(n + 1));
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin >> a[i][j];
V<int> ans(5);
int base = 0;
auto swap_col = [&](int x, int y) -> void {
V<int> tmp(n + 1);
for(int i = 1; i <= n; i++) tmp[i] = a[i][x];
for(int i = 1; i <= n; i++) a[i][x] = a[i][y];
for(int i = 1; i <= n; i++) a[i][y] = tmp[i];
};
auto swap_row = [&](int x, int y) -> void {
swap(a[x], a[y]);
};
auto add_col = [&](int x, int v) -> void {
base = (base + v) % 5;
for(int i = 1; i <= n; i++) a[i][x] = (a[i][x] + v) % 5;
};
auto add_row = [&](int x, int v) -> void {
base = (base + v) % 5;
for(int i = 1; i <= n; i++) a[x][i] = (a[x][i] + v) % 5;
};
auto show_ans = [&]() -> void {
for(int i = 0; i < 5; i++) cout << (ans[i] ? "Y" : "N");
cout << endl;
};
auto add_ans = [&](int x) -> void {
ans[(5 + x - base) % 5] = 1;
};
if(n <= 10) {
V<int> pos(n + 1);
iota(all1(pos), 1);
do{
int cnt = 0;
for(int i = 1; i <= n; i++) cnt += a[i][pos[i]];
cnt %= 5;
add_ans(cnt);
} while(next_permutation(all1(pos)));
show_ans();
return;
}
auto shift_val = [&](int x, int shift) -> int {
return (x << shift | x >> (5 - shift)) & (1 << 5) - 1;
};
auto deal_six = [&]() -> void {
V<int> dp_row(1 << 6), dp_col(1 << 6);
dp_row[0] = 1, dp_col[0] = 1;
auto upd_dp = [&](V<int> &dp, array<int, 6> ar) -> void {
V<int> n_dp(1 << 6);
for(int i = 0; i < 1 << 6; i++) {
n_dp[i] |= dp[i];
for(int j = 0; j < 6; j++) {
if(i & (1 << j)) continue;
n_dp[i | (1 << j)] |= shift_val(dp[i], ar[j]);
}
}
swap(dp, n_dp);
};
for(int i = 7; i <= n; i++) {
array<int, 6> ar;
for(int j = 1; j <= 6; j++) ar[j - 1] = a[j][i];
upd_dp(dp_row, ar);
}
for(int i = 7; i <= n; i++) {
array<int, 6> ar;
for(int j = 1; j <= 6; j++) ar[j - 1] = a[i][j];
upd_dp(dp_col, ar);
}
for(int i = 0; i < 1 << 6; i++) {
for(int j = 0; j < 1 << 6; j++) {
if(__popcount(i) != __popcount(j)) {
continue;
}
V<int> row, col;
for(int k = 1; k <= 6; k++) if(!(i >> (k - 1) & 1)) row.pb(k);
for(int k = 1; k <= 6; k++) if(!(j >> (k - 1) & 1)) col.pb(k);
do {
int cur = MOD(dp_row[i] + dp_col[j]);
for(int i = 0; i < row.size(); i++) {
cur = MOD(cur + a[row[i]][col[i]]);
}
add_ans(cur);
} while(next_permutation(all0(row)));
}
}
};
for(int i = 1; i <= 4; i++) {
int s = (i - 1) * 2 + 1;
for(int i = s; i <= n; i++) {
add_col(i, 5 - a[s][i]);
}
for(int i = s; i <= n; i++) {
add_row(i, 5 - a[i][s]);
}
bool ok = 0;
for(int i = s + 1; i <= n; i++) {
bool dif = 0;
for(int j = s; j <= n; j++) if(a[i][j]) dif = 1;
if(dif) {
swap_row(s + 1, i);
ok = 1;
break;
}
}
if(!ok) {
deal_six();
show_ans();
return;
}
for(int i = s; i <= n; i++) if(a[s + 1][i]) {
swap_col(i, s + 1);
break;
}
}
cout << "YYYYY" << endl;
}
int32_t main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t=1;
//cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
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: 0
Accepted
time: 0ms
memory: 3608kb
input:
4 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #5:
score: 0
Accepted
time: 32ms
memory: 3612kb
input:
10 1 4 2 0 0 2 0 1 3 3 0 3 1 4 4 1 4 0 2 2 1 4 2 0 0 2 0 1 0 3 0 3 1 4 4 1 4 0 2 2 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 1 4 2 0 0 2 0 1 3 3 3 1 4 2 2 4 2 3 0 0
output:
NYNNY
result:
ok "NYNNY"
Test #6:
score: 0
Accepted
time: 31ms
memory: 3684kb
input:
10 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 3 3 3 0 2 3 0 3 2 4 4 4 4 1 3 4 1 4 3 0 2 2 2 4 1 2 4 2 1 3 2 2 2 4 1 3 4 2 1 3 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 2 2 2 4 1 2 4 2 1 3 4 4 4 1 3 4 1 1 3 0
output:
YYYNY
result:
ok "YYYNY"
Test #7:
score: 0
Accepted
time: 33ms
memory: 3652kb
input:
10 1 2 0 4 2 3 4 0 2 3 0 1 4 3 1 2 3 4 1 2 4 0 3 2 0 1 2 3 0 1 1 2 0 4 2 3 4 0 2 3 3 4 2 1 4 0 1 2 4 0 0 1 4 3 1 2 3 4 1 2 2 3 1 0 3 4 0 1 3 4 3 1 1 1 4 0 1 2 4 0 1 2 0 4 2 3 4 0 2 3 1 3 0 4 2 3 4 0 2 3
output:
NYYYY
result:
ok "NYYYY"
Test #8:
score: 0
Accepted
time: 28ms
memory: 3556kb
input:
10 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 2 3 4 2 1 1 4 3 4 1 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4
output:
NYNNN
result:
ok "NYNNN"
Test #9:
score: 0
Accepted
time: 32ms
memory: 3816kb
input:
10 4 1 3 1 2 0 3 2 4 4 0 2 4 2 3 1 4 3 0 0 1 1 1 1 2 0 3 2 4 1 2 4 1 4 0 3 1 0 2 2 1 3 0 3 4 2 0 4 1 1 2 4 1 4 0 3 1 0 2 2 2 4 1 4 0 3 1 0 2 2 0 2 4 2 3 1 4 3 0 0 3 0 2 1 1 4 2 1 3 3 4 1 3 1 2 0 3 2 4 4
output:
YYYYY
result:
ok "YYYYY"
Test #10:
score: 0
Accepted
time: 32ms
memory: 3848kb
input:
10 1 2 0 2 4 2 3 1 2 1 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 0 1 4 1 3 1 2 0 1 0
output:
NNNYN
result:
ok "NNNYN"
Test #11:
score: 0
Accepted
time: 32ms
memory: 3616kb
input:
10 1 4 1 2 1 3 3 2 1 2 0 3 0 1 0 2 2 1 0 1 0 4 0 3 0 2 2 1 0 1 1 4 1 2 1 3 3 2 1 2 4 2 4 0 4 1 1 0 4 0 1 1 1 4 1 0 3 2 1 2 0 0 0 1 0 2 2 1 0 1 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3
output:
YYYYY
result:
ok "YYYYY"
Test #12:
score: 0
Accepted
time: 32ms
memory: 3560kb
input:
10 1 2 0 1 4 0 1 2 2 2 1 2 0 1 4 3 1 2 2 2 0 1 4 0 3 1 0 1 1 1 1 2 0 1 4 3 1 2 2 2 3 4 2 3 1 4 3 4 4 4 0 1 4 0 3 1 0 1 1 1 4 0 3 4 2 0 4 0 0 0 3 4 2 3 1 4 3 4 4 4 4 0 3 4 2 0 4 0 0 0 0 1 4 0 3 1 0 1 1 1
output:
YNYNY
result:
ok "YNYNY"
Test #13:
score: 0
Accepted
time: 32ms
memory: 3616kb
input:
10 1 3 0 0 2 1 3 4 3 3 3 3 0 0 4 1 3 4 3 3 1 1 3 3 2 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 4 1 3 3 0 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 0 2 4 4 1 0 2 3 2 2 3 0 2 2 4 3 0 1 0 0 3 0 2 2 4 3 0 1 0 0 4 2 4 4 1 0 2 3 2 2
output:
YYYNY
result:
ok "YYYNY"
Test #14:
score: 0
Accepted
time: 32ms
memory: 3560kb
input:
10 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 1 4 2 0 2 4 4 4 3 0 3 3 4 2 4 1 1 1 0 2 3 1 4 2 4 1 1 1 0 2 4 2 0 3 0 2 2 2 1 3 3 1 4 2 4 1 1 1 0 2 1 4 2 0 2 4 4 4 3 0
output:
YNYNN
result:
ok "YNYNN"
Test #15:
score: -100
Wrong Answer
time: 29ms
memory: 7052kb
input:
1000 3 4 1 2 4 1 0 3 0 4 1 4 3 1 4 4 1 0 1 2 3 1 0 1 3 4 4 0 3 0 3 2 2 1 0 4 1 3 3 0 3 1 3 2 2 0 3 3 2 2 3 0 4 2 1 2 1 2 1 4 2 4 1 4 2 4 3 2 0 3 0 4 2 1 2 3 3 0 2 0 3 3 1 1 0 3 4 3 2 0 4 0 3 4 4 2 3 4 2 3 4 2 1 3 2 2 4 1 0 2 2 4 0 1 2 0 4 1 3 2 3 2 2 2 1 4 4 4 2 0 0 4 4 1 3 4 0 2 2 3 1 1 3 2 3 2 3 0...
output:
YNNNN
result:
wrong answer 1st words differ - expected: 'NNNYN', found: 'YNNNN'