結果

問題 No.2519 Coins in Array
ユーザー GOTKAKOGOTKAKO
提出日時 2023-10-27 23:21:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 2,069 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 206,220 KB
実行使用メモリ 4,776 KB
最終ジャッジ日時 2023-10-27 23:21:37
合計ジャッジ時間 8,568 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 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 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 282 ms
4,776 KB
testcase_24 AC 282 ms
4,776 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 285 ms
4,776 KB
testcase_28 AC 284 ms
4,776 KB
testcase_29 AC 281 ms
4,776 KB
testcase_30 AC 255 ms
4,512 KB
testcase_31 AC 45 ms
4,348 KB
testcase_32 AC 138 ms
4,348 KB
testcase_33 AC 197 ms
4,348 KB
testcase_34 AC 94 ms
4,348 KB
testcase_35 AC 204 ms
4,348 KB
testcase_36 AC 75 ms
4,348 KB
testcase_37 AC 34 ms
4,348 KB
testcase_38 AC 149 ms
4,348 KB
testcase_39 AC 86 ms
4,348 KB
testcase_40 AC 280 ms
4,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<long long> A(N);
    for(auto &a : A) cin >> a;
    if(N == 2){
        long long answer = (A.at(0)-1)*(A.at(1)-1);
        if(A.at(0) <= 1 || A.at(1) <= 1) answer = 0; 
        if(gcd(A.at(0),A.at(1)) > 1) answer = 0;

        cout << answer << endl;
        cout << "1 2" << endl;
    }
    else if(N == 3){
        long long a0 = A.at(0),a1 = A.at(1),a2 = A.at(2);
        if(a0 <= 1 || a1 <= 1 || a2 <= 1){
            cout << 0 << endl << "1 2" << endl << "1 2" << endl;
        }
        else if(a0%2 == 0 || a1%2 == 0 || a2%2 == 0){
            cout << 0 << endl;
            if(a0%2 == 0) cout << "2 3" << endl;
            else if(a1%2 == 0) cout << "1 3" << endl;
            else cout << "1 2" << endl;
            cout << "1 2" << endl;
        }
        else{
            long long answer = 8e18,left = -1;
            for(int i=0; i<3; i++){
                long long now = 1;
                if(gcd(A.at(i),A.at((i+1)%3)) > 1){
                    answer = 0,left = (i+2)%3;
                    break;
                }
                now = (A.at(i)-1)*(A.at((i+1)%3)-1);
                if(gcd(now,A.at((i+2)%3)) > 1){
                    answer = 0,left = (i+2)%3;
                    break;
                }
                now = (now-1)*(A.at((i+2)%3)-1);
                if(now < answer) answer = now,left = (i+2)%3;
            }

            bool output = false;
            cout << answer << endl;
            for(int i=0; i<3; i++){
                if(left == i) continue;
                if(output) cout << " ";
                output = true;
                cout << i+1;
            }
            cout << endl << "1 2" << endl;
        }
    }
    else{
        cout << 0 << endl;
        cout << "1 2" << endl << "1 2" << endl;
        cout << N-3 << " " << N-2 << endl;
        N -= 3;
        while(N != 1){
            cout << 1 << " " << N << endl;
            N--; 
        }
    }
}
0