結果

問題 No.2519 Coins in Array
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-03 14:51:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 206,564 KB
実行使用メモリ 6,444 KB
最終ジャッジ日時 2023-09-05 16:53:13
合計ジャッジ時間 9,141 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 340 ms
6,148 KB
testcase_24 AC 337 ms
6,444 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 334 ms
6,204 KB
testcase_28 AC 337 ms
6,184 KB
testcase_29 AC 336 ms
6,224 KB
testcase_30 AC 308 ms
5,872 KB
testcase_31 AC 54 ms
4,380 KB
testcase_32 AC 163 ms
4,592 KB
testcase_33 AC 231 ms
5,304 KB
testcase_34 AC 113 ms
4,380 KB
testcase_35 AC 222 ms
5,260 KB
testcase_36 AC 89 ms
4,376 KB
testcase_37 AC 40 ms
4,380 KB
testcase_38 AC 177 ms
4,652 KB
testcase_39 AC 103 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll f(ll x, ll y) {
	return (gcd(x, y) == 1) ? (x - 1) * (y - 1) : 0;
}


int main(){
    int n;  cin >> n;
    vector<ll> a(n);
    for(auto& x : a){
        cin >> x;
    }
    
    ll ans = 0;
    vector<pair<int, int> > ops(n - 1, pair<int, int>({}));
    if(n == 2){
        ans = f(a[0], a[1]);
        ops = { {1, 2} };
    }
    else if(n == 3){
        ans = f(f(a[0], a[1]), a[2]);
        ops = { {1, 2}, {1, 2} };
        ll t = f(f(a[0], a[2]), a[1]);
        if(t < ans){
            ans = t;
            ops = { {1, 3}, {1, 2} };
        } 
        t = f(f(a[1], a[2]), a[0]);
        if(t < ans){
            ans = t;
            ops = { {2, 3}, {1, 2} };
        }       
    }
    else{
        ans = 0;
        ops[0] = {1, 2};  ops[1] = {1, 2};  ops[2] = {n - 3, n - 2};
        for(int i = n - 3; i > 1; --i){
            ops[n - i] = {1, i};
        }
    }

    cout << ans << endl;
    for(auto&[x, y] : ops){
        cout << x << ' ' << y << endl;
    }

    return 0;
}
0