QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625365 | #8830. Breaking Bad | ucup-team2432 | RE | 0ms | 0kb | C++17 | 3.5kb | 2024-10-09 18:53:47 | 2024-10-09 18:53:48 |
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define ll long long
#define all(v) v.begin(),v.end()
#define sz(v) ((ll)v.size())
#define V vector
#define vi V<int>
#define vll V<ll>
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define A array
#define pb push_back
#define mset multiset
#define gpumap __gnu_pbds::gp_hash_table
#define ccumap __gnu_pbds::cc_hash_table
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
#define cerr if (test) cerr
#define freopen if (test) freopen
#define whtest if (test)
using namespace std;
const int test = 0;
namespace jhsy {
constexpr int D = 5;
void main() {
int n;
cin >> n;
V<vi> a(n,vi(n));
for (auto &p:a) {
for (auto &x:p) {
cin >> x;
}
}
V<vi> vis(2,vi(n));
for (int i = 0; i+1 < n; i++) {
for (int j = 0; j+1 < n; j++) {
if (!vis[0][i] && !vis[0][i+1] && !vis[1][j] && !vis[1][j+1]) {
if (a[i][j]+a[i+1][j+1] != a[i][j+1]+a[i+1][j]) {
vis[0][i] = vis[0][i+1] = vis[1][j] = vis[1][j+1] = 1;
}
}
}
}
auto print = [](const string &s) {
cout << s << '\n';
};
const int m = accumulate(all(vis[0]),0);
if (m >= 8) {
return print("YYYYY");
}
{
V<vi> p(2,vi(n));
for (int i = 0; i < 2; i++) {
iota(all(p[i]),0);
sort(all(p[i]),[&](int x,int y) {
if (vis[i][x] != vis[i][y]) {
return vis[i][x] > vis[i][y];
}
return x < y;
});
}
{
V t(n,vi(n));
for (int i = 0; i < n; i++) {
t[i] = a[p[0][i]];
}
a = std::move(t);
}
for (int i = 0; i < n; i++) {
vi t(n);
for (int j = 0; j < n; j++) {
t[j] = a[i][p[1][j]];
}
a[i] = std::move(t);
}
}
V<vi> v(2,vi(n)); v[1] = a[m];
for (int i = m; i < n; i++) {
v[0][i] = (a[i][m]+D-v[1][m])%D;
}
const int CS = 1<<m,S = CS-1;
V f(2,V(CS,vi(D)));
for (int o = 0; o < 2; o++) {
f[o][0][0] = 1;
for (int i = n-1; i >= m; i--) {
V<vi> g(CS,vi(D));
for (int j = 0; j <= S; j++) {
for (int k = 0; k < D; k++) {
if (f[o][j][k]) {
for (int t = 0; t < m; t++) {
if (!o) {
g[j|(1<<t)][(k+a[i][t])%D] = 1;
}
else {
g[j|(1<<t)][(k+a[t][i])%D] = 1;
}
}
g[j][(k+v[o][i])%D] = 1;
}
}
}
f[o] = std::move(g);
}
}
string ans(D,'N');
for (int i = 0; i <= S; i++) {
auto get = [&](int s) {
vi res;
for (int i = 0; i < m; i++) {
if ((~s>>i)&1) {
res.eb(i);
}
}
return res;
};
vi v0 = get(i);
for (int j = 0; j <= S; j++) {
vi v1 = get(j);
if (sz(v0) == sz(v1)) {
vi can(D);
do {
int s = 0;
for (int k = 0; k < sz(v0); k++) {
s = (s+a[v0[k]][v1[k]])%D;
}
can[s] = 1;
} while (next_permutation(all(v1)));
for (int x = 0; x < D; x++) {
for (int y = 0; y < D; y++) {
for (int z = 0; z < D; z++) {
if (f[0][i][x] && f[1][j][y] && can[z]) {
ans[(x+y+z)%D] = 'Y';
}
}
}
}
}
}
}
return print(ans);
}
}
int main() {
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
// jhsy::init();
int T = 1;
// cin >> T;
while (T--) {
jhsy::main();
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
2 0 4 4 0