結果

問題 No.5020 Averaging
ユーザー PechiPechi
提出日時 2024-02-25 16:28:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 954 ms / 1,000 ms
コード長 4,659 bytes
コンパイル時間 3,372 ms
コンパイル使用メモリ 231,496 KB
実行使用メモリ 6,676 KB
スコア 37,815,139
最終ジャッジ日時 2024-02-25 16:29:42
合計ジャッジ時間 53,688 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 953 ms
6,676 KB
testcase_01 AC 953 ms
6,676 KB
testcase_02 AC 953 ms
6,676 KB
testcase_03 AC 952 ms
6,676 KB
testcase_04 AC 953 ms
6,676 KB
testcase_05 AC 952 ms
6,676 KB
testcase_06 AC 953 ms
6,676 KB
testcase_07 AC 953 ms
6,676 KB
testcase_08 AC 953 ms
6,676 KB
testcase_09 AC 953 ms
6,676 KB
testcase_10 AC 953 ms
6,676 KB
testcase_11 AC 953 ms
6,676 KB
testcase_12 AC 953 ms
6,676 KB
testcase_13 AC 953 ms
6,676 KB
testcase_14 AC 953 ms
6,676 KB
testcase_15 AC 952 ms
6,676 KB
testcase_16 AC 953 ms
6,676 KB
testcase_17 AC 953 ms
6,676 KB
testcase_18 AC 953 ms
6,676 KB
testcase_19 AC 953 ms
6,676 KB
testcase_20 AC 954 ms
6,676 KB
testcase_21 AC 953 ms
6,676 KB
testcase_22 AC 953 ms
6,676 KB
testcase_23 AC 953 ms
6,676 KB
testcase_24 AC 952 ms
6,676 KB
testcase_25 AC 952 ms
6,676 KB
testcase_26 AC 953 ms
6,676 KB
testcase_27 AC 953 ms
6,676 KB
testcase_28 AC 953 ms
6,676 KB
testcase_29 AC 953 ms
6,676 KB
testcase_30 AC 953 ms
6,676 KB
testcase_31 AC 953 ms
6,676 KB
testcase_32 AC 953 ms
6,676 KB
testcase_33 AC 953 ms
6,676 KB
testcase_34 AC 954 ms
6,676 KB
testcase_35 AC 952 ms
6,676 KB
testcase_36 AC 953 ms
6,676 KB
testcase_37 AC 953 ms
6,676 KB
testcase_38 AC 953 ms
6,676 KB
testcase_39 AC 953 ms
6,676 KB
testcase_40 AC 953 ms
6,676 KB
testcase_41 AC 953 ms
6,676 KB
testcase_42 AC 953 ms
6,676 KB
testcase_43 AC 953 ms
6,676 KB
testcase_44 AC 952 ms
6,676 KB
testcase_45 AC 952 ms
6,676 KB
testcase_46 AC 953 ms
6,676 KB
testcase_47 AC 953 ms
6,676 KB
testcase_48 AC 953 ms
6,676 KB
testcase_49 AC 953 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<unordered_map>
#include<random>
#include <array>
#include <complex>
#include<chrono>
using namespace std;
#define LP(I,S,G) for (long long int I = (S); I < (G); ++I)
#define IN(X) 	for (int in = 0; in < X.size(); in++)cin >> X[in]
#define OUT(X) 	for (int in = 0; in < X.size(); in++)cout << X[in]<<" "
#define SORT(X) sort((X).begin(), (X).end())
#define CSORT(X,Y) sort(X.begin(), X.end(),Y)
#define COPY(X,Y) copy(X.begin(), X.end(), Y.begin())
#define ALL(X,Y) for (auto (X) :(Y))
#define FULL(a)  (a).begin(),(a).end()
#define BFS(Q,S) for(Q.push(S);Q.size()!=0;Q.pop())
typedef long long int ll;
typedef unsigned long long int ull;
long long int M = 998244353;

chrono::system_clock::time_point starttime;
using namespace std::chrono;
#ifndef ONLINE_JUDGE
#define DEBUG
#endif

inline float getTime() {
#ifdef DEBUG
	return duration_cast<milliseconds>(system_clock::now() - starttime).count() / 4.0;
#else
	return duration_cast<milliseconds>(system_clock::now() - starttime).count();
#endif
}


int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };

ll MAX(ll A, ll B) { return ((A) > (B) ? (A) : (B)); }
ll MIN(ll A, ll B) { return ((A) < (B) ? (A) : (B)); }
inline long long int xor128() {
	static long long int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	long long int t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

long long int pow_n(long long int x, long long int n) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return pow_n(x * x, n / 2);
	else
		return x * pow_n(x, n - 1);
}

ll border = 5 * pow_n(10, 17);

double calc_score(vector<ll> a, vector<ll> b, array<pair<ll, ll>,50>& ans) {
	for (int i = 0; i < ans.size(); ++i) {
		int u = ans[i].first, v = ans[i].second;
		a[u] = a[v] = (a[u] + a[v]) / 2;
		b[u] = b[v] = (b[u] + b[v]) / 2;
	}
	return log10(max(abs(border - a[0]), abs(border - b[0])) + 1);
}

struct Data {
	int n = 45, t = 50;
	double score;
	array<pair<ll, ll>, 50> ans;
	Data(vector<ll>& a,vector<ll>& b) {
		LP(i, 0, t) {
			ans[i].first = xor128() % n;
			ans[i].second = xor128() % (n - 1);
			if (ans[i].second >= ans[i].first)++ans[i].second;
		}
		score = calc_score(a, b, ans);
	}
	bool operator<(Data& r) {
		return score < r.score;
	}
	bool operator>(Data& r) {
		return score > r.score;
	}
	bool operator==(Data& r) {
		return score == r.score;
	}
};

int main(int argc, char* argv[]) {
	starttime = chrono::system_clock::now();
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	mt19937 rnd(0);
	int wid = 4, p = 1;
	ll n, t = 50, now = 0;
	cin >> n;
	vector<ll> a(n), b(n);
	LP(i, 0, n)cin >> a[i] >> b[i];
	vector<Data> data;
	for (int i = 0; i < wid; ++i)data.push_back(Data(a, b));
	vector<int> table(t);
	for (int i = 0; i < t; ++i)table[i] = i;
	double time;
	shuffle(table.begin(), table.end(), rnd);
	int cnt = 0;
	double base_time = 0;
	double max_time = 300;
	double c = 0.75;
	while (p != 4) {
		while ((time = getTime() - base_time) <= max_time) {
			double temp = c * (max_time - time) / max_time;
			int i = table[now];
			for (int id = 0; id < wid; ++id) {
				int bx = data[id].ans[i].first, by = data[id].ans[i].second;
				data[id].ans[i].first = xor128() % n;
				data[id].ans[i].second = xor128() % (n - 1);
				if (data[id].ans[i].first != 0 && data[id].ans[i].second != 0 && xor128() % 2)data[id].ans[i].first = 0;
				if (data[id].ans[i].second >= data[id].ans[i].first)++data[id].ans[i].second;
				double new_score = calc_score(a, b, data[id].ans);
				if (xor128() % 10000 < exp((data[id].score - new_score) / temp) * 10000) {
					data[id].score = new_score;
				}
				else {
					data[id].ans[i].first = bx;
					data[id].ans[i].second = by;
				}

			}
#ifdef DEBUG
			++cnt;
#endif // DEBUG
			if (++now == t) {
				now = 0;
				shuffle(table.begin(), table.end(), rnd);
			}
		}
		SORT(data);
		if (p == 1)base_time = 300;
		if (p == 2)base_time = 600, max_time = 350, c = 0.75;
		++p;
		if(p!=4)wid /= 2;

	}
#ifdef DEBUG
	cerr << cnt << "\n";
	SORT(data);
	for (int id = 0; id < wid; ++id) {
		vector<ll> sa = a, sb = b;
		for (int i = 0; i < data[id].ans.size(); ++i) {
			int u = data[id].ans[i].first, v = data[id].ans[i].second;
			sa[u] = sa[v] = (sa[u] + sa[v]) / 2;
			sb[u] = sb[v] = (sb[u] + sb[v]) / 2;
		}
		cerr << "score:" << ll(2000000 - 100000 * log10(max(abs(border - sa[0]), abs(border - sb[0])) + 1)) << "\n";
		cerr << sa[0] << " " << sb[0] << "\n";

	}
#endif // DEBUG
	cout << data[0].ans.size() << "\n";
	ALL(x, data[0].ans)cout << x.first + 1 << " " << x.second + 1 << "\n";
	exit(0);
}
0