結果

問題 No.5020 Averaging
ユーザー anonymously
提出日時 2024-02-25 13:41:14
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,116 bytes
コンパイル時間 2,593 ms
コンパイル使用メモリ 207,024 KB
実行使用メモリ 6,676 KB
スコア 18,741,092
最終ジャッジ日時 2024-02-25 13:41:21
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const long TARGET=500000000000000000L;

struct card{
	long surface;
	long back;
};

void rewrite(card& u, card& v){
	long a=u.surface;
	long b=v.surface;
	long surface=(a+b)/2;
	u.surface=surface;
	v.surface=surface;

	long c=u.back;
	long d=v.back;
	long back=(c+d)/2;
	u.back=back;
	v.back=back;
}

long score(const card& u, const card& v){
	long temp=max(abs(u.surface-TARGET),abs(u.back-TARGET));
	long tmp=max(abs((u.surface+v.surface)/2-TARGET),abs((u.back+v.back)/2-TARGET));
	return temp-tmp;
}

int main(){
	int n;
	cin >> n;
	assert(n==45);
	vector<card> cards(n);
	for(int i=0;i<n;i++){
		cin >> cards[i].surface >> cards[i].back;
	}
	vector<pair<int,int>> V;
	while(true){
		long hiscore=0;
		int k=0;
		for(int i=1;i<n;i++){
			long s=score(cards[0],cards[i]);
			if(s>hiscore){
				k=i;
			}
		}
		if(k){
			V.push_back(make_pair(1,k+1));
			rewrite(cards[0],cards[k]);
		}else{
			break;
		}
		if(V.size()==50){
			break;
		}
	}
	cout << V.size() << endl;
	for(pair<int,int> v:V){
		cout << v.first << ' ' << v.second << endl;
	}
	return EXIT_SUCCESS;
}
0