結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,548 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,548 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 WA -
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 WA -
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 294 ms
6,548 KB
testcase_24 WA -
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 296 ms
6,548 KB
testcase_28 AC 294 ms
6,548 KB
testcase_29 AC 292 ms
6,548 KB
testcase_30 AC 264 ms
6,548 KB
testcase_31 AC 47 ms
6,548 KB
testcase_32 AC 142 ms
6,548 KB
testcase_33 AC 206 ms
6,548 KB
testcase_34 AC 100 ms
6,548 KB
testcase_35 AC 188 ms
6,548 KB
testcase_36 AC 80 ms
6,548 KB
testcase_37 AC 36 ms
6,548 KB
testcase_38 AC 155 ms
6,548 KB
testcase_39 AC 89 ms
6,548 KB
testcase_40 AC 285 ms
6,548 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 << "0 1" << 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;
    }
    for (int i = 0; i < n - 1; i++) {
        long long ai = a.back();
        a.pop_back();
        long long aj = a.back();
        a.pop_back();
        a.push_back(f(ai, aj));
    }
    cout << a[0] << endl;
    for (int i = n - 1; i >= 1; i--) {
        cout << i << " " << i + 1 << endl;
    }
}
0