QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625339#8830. Breaking Baducup-team2432WA 0ms3848kbC++173.4kb2024-10-09 18:47:032024-10-09 18:47:04

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 18:47:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3848kb
  • [2024-10-09 18:47:03]
  • 提交

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));
		for (int i = m; i < n; i++) {
			v[0][i] = (a[i][0]+D-v[1][0])%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++) {
								g[j|(1<<t)][(k+a[i][t])%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: 100
Accepted
time: 0ms
memory: 3560kb

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3848kb

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

NYYYN

result:

wrong answer 1st words differ - expected: 'YYYYN', found: 'NYYYN'