結果

問題 No.2519 Coins in Array
ユーザー SSRSSSRS
提出日時 2023-10-27 21:33:25
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,099 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 204,728 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 13:37:42
合計ジャッジ時間 10,518 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 32 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 {
      return (x - 1) * (y - 1);
    }
  };
  if (N >= 4){
    cout << 0 << endl;
    cout << 1 << ' ' << 2 << endl;
    cout << 3 << ' ' << 4 << endl;
    cout << N - 3 << ' ' << N - 2 << endl;
    for (int i = N - 3; i >= 2; i--){
      cout << i << ' ' << i - 1 << 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 && b <= 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;
    }
  }
}
0