結果

問題 No.2519 Coins in Array
ユーザー eve__fuyukieve__fuyuki
提出日時 2023-11-29 05:17:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 205,616 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-29 05:17:12
合計ジャッジ時間 8,268 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 263 ms
6,676 KB
testcase_24 AC 263 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 262 ms
6,676 KB
testcase_28 AC 261 ms
6,676 KB
testcase_29 AC 260 ms
6,676 KB
testcase_30 AC 239 ms
6,676 KB
testcase_31 AC 42 ms
6,676 KB
testcase_32 AC 128 ms
6,676 KB
testcase_33 AC 184 ms
6,676 KB
testcase_34 AC 87 ms
6,676 KB
testcase_35 AC 170 ms
6,676 KB
testcase_36 AC 70 ms
6,676 KB
testcase_37 AC 33 ms
6,676 KB
testcase_38 AC 140 ms
6,676 KB
testcase_39 AC 80 ms
6,676 KB
testcase_40 AC 257 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
long long f(long long x, long long y) {
    if (gcd(x, y) == 1) {
        return (x - 1) * (y - 1);
    }
    return 0;
}
int main() {
    fast_io();
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (n == 2) {
        cout << f(a[0], a[1]) << endl;
        cout << "1 2" << endl;
        return 0;
    }
    if (n == 3) {
        vector<long long> ff{f(a[0], f(a[1], a[2])), f(a[1], f(a[0], a[2])),
                             f(a[2], f(a[0], a[1]))};
        int idx = min_element(ff.begin(), ff.end()) - ff.begin();
        cout << ff[idx] << endl;
        if (idx == 0) {
            cout << "2 3" << endl;
        } else if (idx == 1) {
            cout << "1 3" << endl;
        } else {
            cout << "1 2" << endl;
        }
        cout << "1 2" << endl;
        return 0;
    }
    cout << 0 << endl;
    for (int i = 1; i < n; i++) {
        cout << "1 2" << endl;
    }
}
0