QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#522949#8830. Breaking Badsmosp#RE 0ms0kbC++202.1kb2024-08-17 17:15:402024-08-17 17:15:41

Judging History

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

  • [2024-08-17 17:15:41]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-17 17:15:40]
  • 提交

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';
	}
	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, 0);

	// {
	// 	// Pick random T * T from first ~20 rows/columns?
	// }

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

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
0 4
4 0

output:


result: