結果

問題 No.2519 Coins in Array
ユーザー tnakao0123tnakao0123
提出日時 2023-10-30 14:04:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 44,812 KB
実行使用メモリ 5,568 KB
最終ジャッジ日時 2023-10-30 14:04:36
合計ジャッジ時間 4,639 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 52 ms
5,568 KB
testcase_24 AC 52 ms
5,568 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 1 ms
4,372 KB
testcase_27 AC 52 ms
5,568 KB
testcase_28 AC 52 ms
5,568 KB
testcase_29 AC 52 ms
5,568 KB
testcase_30 AC 48 ms
5,352 KB
testcase_31 AC 9 ms
4,372 KB
testcase_32 AC 26 ms
4,372 KB
testcase_33 AC 37 ms
4,864 KB
testcase_34 AC 18 ms
4,372 KB
testcase_35 AC 34 ms
4,724 KB
testcase_36 AC 15 ms
4,372 KB
testcase_37 AC 7 ms
4,372 KB
testcase_38 AC 28 ms
4,468 KB
testcase_39 AC 17 ms
4,372 KB
testcase_40 AC 45 ms
5,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2519.cc:  No.2519 Coins in Array - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;

/* global variables */

int as[MAX_N];
pii ops[MAX_N];

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m >= 0, n >= 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

ll f(ll x, ll y) {
  ll g = gcd(x, y);
  return (g == 1) ? (x - 1) * (y - 1) : 0;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  ll mina = 0;
  if (n == 2) {
    mina = f(as[0], as[1]);
    ops[0] = pii(0, 1);
  }
  else if (n == 3) {
    ll f0 = f(f(as[0], as[1]), as[2]);
    ll f1 = f(f(as[0], as[2]), as[1]);
    ll f2 = f(f(as[1], as[2]), as[0]);
    if (f0 <= min(f1, f2))
      mina = f0, ops[0] = pii(0, 1);
    else if (f1 <= f2)
      mina = f1, ops[0] = pii(0, 2);
    else
      mina = f2, ops[0] = pii(1, 2);
    ops[1] = pii(0, 1);
  }
  else {
    mina = 0;
    for (int i = 0; i < n - 1; i++) ops[i] = pii(0, 1);
  }

  printf("%lld\n", mina);
  for (int i = 0; i < n - 1; i++)
    printf("%d %d\n", ops[i].first + 1, ops[i].second + 1);

  return 0;
}
0