QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#522961#8830. Breaking Badsmosp#WA 58ms11664kbC++202.9kb2024-08-17 17:27:232024-08-17 17:27:23

Judging History

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

  • [2024-08-17 17:27:23]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:11664kb
  • [2024-08-17 17:27:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int rand(int a, int b) {
	int x = abs((int)rng());
	return x % (b - a + 1) + a;
}

const int T = 10;

vi brute_force(int n, vector<vi> &v, int rem) {
	vi p(n);
	iota(all(p), 0);
	vi ans(5, 0);
	do {
		int x = rem;
		rep(i, 0, n) x += v[i][p[i]];
		ans[x % 5] = 1;
	} while(next_permutation(all(p)));
	return ans;
}

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);

	int n;
	cin >> n;
	// If n <= 10 -> Try all. Easy. 
	vector<vi> v(n, vi(n));
	rep(i, 0, n) rep(j, 0, n) {
		cin >> v[i][j];
		v[i][j] %= 5;
	}
	if(n <= T) {
		auto ans = brute_force(n, v, 0);
		for(auto i : ans) cout << (i == 0 ? 'N' : 'Y');
		cout << '\n';
		return 0;
	}
	vector<vi> r(n, vi(5, 0)), c(n, vi(5, 0));
	rep(i, 0, n) rep(j, 0, n) {
		r[i][v[i][j]]++;
		c[j][v[i][j]]++;
	}
	vi bestr(n), bestc(n);
	iota(all(bestr), 0);
	iota(all(bestc), 0);
	sort(all(bestr), [&](int a, int b) {
		int suma = 0;
		int sumb = 0;
		// int nonzeroa = 0;
		// int nonzerob = 0;
		rep(i, 0, 5) {
			suma += r[a][i] * r[a][i];
			sumb += r[b][i] * r[b][i];
			// if(r[a][i] != 0) nonzeroa++;
			// if(r[b][i] != 0) nonzerob++;
		}
		return suma < sumb;
	});
	sort(all(bestc), [&](int a, int b) {
		int suma = 0;
		int sumb = 0;
		rep(i, 0, 5) {
			suma += c[a][i] * c[a][i];
			sumb += c[b][i] * c[b][i];
		}
		return suma < sumb;
	});

	// Now we can try random cases based on this "variation" index. 
	int rem = 0;
	rep(i, T, n) {
		rem += v[bestr[i]][bestc[i]];	
	}
	vector<vi> t(T, vi(T));
	rep(i, 0, T) rep(j, 0, T) {
		t[i][j] = v[bestr[i]][bestc[j]];
	}
	auto ans = brute_force(T, t, rem);

	// rep(_, 0, 4) {
	// 	// Pick random T * T
	// 	int tt = min(T*2, n);
	// 	set <int> r, c;
	// 	while(sz(r) < T) r.insert(rand(0, tt - 1));
	// 	while(sz(c) < T) c.insert(rand(0, tt - 1));
	// 	int rem = 0;
	// 	vector<int> vr(tt, 0);
	// 	vector<int> vc(tt, 0);
	// 	for(auto i : r) vr[i]++;
	// 	for(auto i : c) vc[i]++;
	// 	int ri = 0;
	// 	int ci = 0;
	// 	while(ri < n) {
	// 		if(vr[ri] == 1) {
	// 			ri++;
	// 			continue;
	// 		}
	// 		if(vc[ci] == 1) {
	// 			ci++;
	// 			continue;
	// 		}
	// 		rem += v[bestr[ri]][bestc[ci]];
	// 		ri++;
	// 		ci++;
	// 	}
	// 	vector<vi> u(T, vi(T));
	// 	vi vvr; for(auto i : r) vvr.push_back(i);
	// 	vi vvc; for(auto i : c) vvc.push_back(i);
	// 	rep(i, 0, T) rep(j, 0, T) u[i][j] = v[bestr[vvr[i]]][bestc[vvc[j]]];
	// 	auto ans2 = brute_force(T, t, rem);
	// 	rep(i, 0, 5) ans[i] += ans2[i];
	// }

	for(auto i : ans) cout << (i == 0 ? 'N' : 'Y');
	cout << '\n';

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

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

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

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

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: 3600kb

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: 26ms
memory: 3648kb

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: 25ms
memory: 3652kb

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: 22ms
memory: 3880kb

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: 30ms
memory: 3816kb

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: 26ms
memory: 3640kb

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: 26ms
memory: 3652kb

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: 27ms
memory: 3816kb

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: 27ms
memory: 3644kb

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: 22ms
memory: 3648kb

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: 26ms
memory: 3652kb

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: 0
Accepted
time: 57ms
memory: 11664kb

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:

NNNYN

result:

ok "NNNYN"

Test #16:

score: -100
Wrong Answer
time: 58ms
memory: 11660kb

input:

1000
2 3 0 1 0 0 0 1 1 4 1 4 2 3 0 3 4 2 3 2 4 2 1 1 1 1 0 0 3 3 2 0 2 2 2 4 3 0 3 3 3 0 1 3 0 2 0 1 0 0 0 3 1 4 3 1 4 0 3 4 4 1 3 3 4 0 1 4 2 3 0 1 0 0 2 3 1 4 0 0 2 1 2 3 3 4 4 3 3 2 0 0 4 3 2 3 3 2 4 0 2 2 3 0 3 2 4 1 0 2 4 2 4 1 2 1 3 0 3 3 0 1 1 0 2 3 0 2 4 1 4 3 4 1 2 2 2 4 0 1 3 3 0 0 1 3 2 4...

output:

NYNNN

result:

wrong answer 1st words differ - expected: 'NYYYY', found: 'NYNNN'