結果

問題 No.2519 Coins in Array
ユーザー binapbinap
提出日時 2023-10-27 22:42:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,528 bytes
コンパイル時間 4,052 ms
コンパイル使用メモリ 265,416 KB
実行使用メモリ 5,944 KB
最終ジャッジ日時 2023-10-27 22:42:17
合計ジャッジ時間 8,539 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 87 ms
5,944 KB
testcase_24 AC 82 ms
5,552 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 85 ms
4,920 KB
testcase_28 AC 84 ms
4,920 KB
testcase_29 AC 85 ms
4,920 KB
testcase_30 AC 79 ms
4,656 KB
testcase_31 AC 14 ms
4,348 KB
testcase_32 AC 40 ms
4,348 KB
testcase_33 AC 58 ms
4,392 KB
testcase_34 AC 28 ms
4,348 KB
testcase_35 AC 53 ms
4,392 KB
testcase_36 AC 24 ms
4,348 KB
testcase_37 AC 11 ms
4,348 KB
testcase_38 AC 42 ms
4,348 KB
testcase_39 AC 26 ms
4,348 KB
testcase_40 AC 60 ms
5,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

template <int m>
std::ostream& operator<<(std::ostream& os, const atcoder::static_modint<m>& a) {os << a.val(); return os;}
template<typename T>
istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}


int main(){
	int n;
	cin >> n;
	vl a(n);
	cin >> a;
	auto func = [&](ll x, ll y){
		if(x == 0 or y == 0) return (long long)0;
		ll g = gcd(x, y);
		if(g >= 2) return (long long)0;
		else return (x - 1) * (y - 1);
	};
	if(n >= 4){
		vi e;
		vi o;
		rep(i, n){
			if(a[i] % 2 == 0){
				e.push_back(i);
				if(int(e.size()) >= 2 and int(o.size()) >= 4) break;
			}else{
				o.push_back(i);
				if(int(e.size()) >= 2 and int(o.size()) >= 4) break;
				
			}
		}
		cout << "0\n";
		if(int(e.size()) >= 2){
			cout << e[0] + 1 << ' ' << e[1] + 1 << "\n";
			rep(i, n - 2){
				cout << 1 << ' ' << n - 1 - i << "\n";
			}
			return 0;
		}
		if(int(e.size()) == 1){
			cout << o[0] + 1 << ' ' << o[1] + 1 << "\n";
			int cnt = 0;
			if(o[0] < e[0]) cnt++;
			if(o[1] < e[0]) cnt++;
			e[0] -= cnt;
			cout << e[0] + 1 << ' ' << n - 1 << "\n";
			rep(i, n - 3){
				cout << 1 << ' ' << n - 2 - i << "\n";
			}
			return 0;
		}
		cout << o[0] + 1 << ' ' << o[1] + 1 << "\n";
		o[2] -= 2;
		o[3] -= 2;
		cout << o[2] + 1 << ' ' << o[3] + 1 << "\n";
		cout << n - 3 << ' ' << n - 2 << "\n";
		rep(i, n - 4){
			cout << 1 << ' ' << n - 3 - i << "\n";
		}
		return 0;
	}
	vi perm(n);
	rep(i, n) perm[i] = i;
	vi ans_perm = perm;
	ll ans = 1001001001001001001;
	do{
		long long tmp = 0;
		if(n == 2) tmp = func(a[perm[0]], a[perm[1]]);
		if(n == 3) tmp = func(func(a[perm[0]], a[perm[1]]), a[perm[2]]);
		if(tmp < ans){
			ans = tmp;
			ans_perm = perm;
		}
	}while(next_permutation(perm.begin(), perm.end()));
	cout << ans << "\n";
	cout << ans_perm[0] + 1 << ' ' << ans_perm[1] + 1 << "\n";
	if(n == 3) cout << "1 2\n";
	return 0;
}
0