結果

問題 No.2519 Coins in Array
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-19 20:27:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 3,105 ms
コンパイル使用メモリ 205,980 KB
実行使用メモリ 6,312 KB
最終ジャッジ日時 2023-09-19 20:27:29
合計ジャッジ時間 10,906 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 337 ms
6,276 KB
testcase_24 AC 336 ms
6,264 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 337 ms
6,312 KB
testcase_28 AC 342 ms
6,224 KB
testcase_29 AC 333 ms
6,176 KB
testcase_30 AC 297 ms
5,904 KB
testcase_31 AC 55 ms
4,380 KB
testcase_32 AC 159 ms
4,652 KB
testcase_33 AC 232 ms
5,064 KB
testcase_34 AC 110 ms
4,376 KB
testcase_35 AC 217 ms
4,900 KB
testcase_36 AC 90 ms
4,380 KB
testcase_37 AC 40 ms
4,384 KB
testcase_38 AC 174 ms
4,688 KB
testcase_39 AC 100 ms
4,388 KB
testcase_40 AC 306 ms
6,120 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;
        for(auto& op : ops){
            op = {1, 2};
        }
    }

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

    return 0;
}
0