結果
問題 | No.2519 Coins in Array |
ユーザー |
![]() |
提出日時 | 2023-10-27 21:37:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 345 ms / 2,000 ms |
コード長 | 1,161 bytes |
コンパイル時間 | 2,040 ms |
コンパイル使用メモリ | 196,564 KB |
最終ジャッジ日時 | 2025-02-17 14:42:23 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; i++){cin >> A[i];}auto f = [&](long long x, long long y){if (gcd(x, y) > 1){return (long long) 0;} else if (x == 0 || y == 0){return (long long) 0;} else {return (x - 1) * (y - 1);}};if (N >= 4){cout << 0 << endl;cout << 1 << ' ' << 2 << endl;cout << 1 << ' ' << 2 << endl;cout << N - 3 << ' ' << N - 2 << endl;for (int i = N - 3; i >= 2; i--){cout << i - 1 << ' ' << i << endl;}} else if (N == 2){cout << f(A[0], A[1]) << endl;cout << 1 << ' ' << 2 << endl;} else {long long a = f(f(A[0], A[1]), A[2]);long long b = f(f(A[1], A[2]), A[0]);long long c = f(f(A[2], A[0]), A[1]);cout << min({a, b, c}) << endl;if (a <= b && a <= c){cout << 1 << ' ' << 2 << endl;cout << 1 << ' ' << 2 << endl;} else if (b <= c){cout << 2 << ' ' << 3 << endl;cout << 1 << ' ' << 2 << endl;} else {cout << 1 << ' ' << 3 << endl;cout << 1 << ' ' << 2 << endl;}}}