結果

問題 No.2519 Coins in Array
ユーザー 👑 chro_96chro_96
提出日時 2023-10-27 22:40:37
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,828 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 31,108 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-27 22:40:42
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 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 2 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 44 ms
4,348 KB
testcase_24 AC 44 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 45 ms
4,348 KB
testcase_28 AC 44 ms
4,348 KB
testcase_29 AC 44 ms
4,348 KB
testcase_30 AC 40 ms
4,348 KB
testcase_31 AC 9 ms
4,348 KB
testcase_32 AC 22 ms
4,348 KB
testcase_33 AC 31 ms
4,348 KB
testcase_34 AC 16 ms
4,348 KB
testcase_35 AC 29 ms
4,348 KB
testcase_36 AC 13 ms
4,348 KB
testcase_37 AC 7 ms
4,348 KB
testcase_38 AC 24 ms
4,348 KB
testcase_39 AC 15 ms
4,348 KB
testcase_40 AC 38 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long long gcd (long long a, long long b) {
  if (b <= 0LL) {
    return a;
  }
  return gcd(b, a%b);
}

int main () {
  int n = 0;
  long long a[200000] = {};
  
  int res = 0;
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", a+i);
  }
  
  if (gcd(a[0], a[1]) != 1LL || a[0]*a[1] == 0LL) {
    printf("0\n");
    printf("1 2\n");
    n--;
    while (n > 1) {
      printf("1 %d\n", n);
      n--;
    }
  } else if (n <= 2) {
    printf("%lld\n", (a[0]-1LL)*(a[1]-1LL));
    printf("1 2\n");
  } else if (n > 3) {
    printf("0\n");
    if (a[0]%2LL == 0LL && a[2]%2LL == 0LL) {
      printf("1 3\n");
      n--;
    } else if (a[0]%2LL == 0LL || (a[1]%2LL == 0LL && a[2]%2LL == 0LL)) {
      printf("2 3\n");
      n--;
    } else if (a[1]%2LL == 0LL) {
      printf("1 3\n");
      n--;
    } else if (a[2]%2LL == 0LL) {
      printf("1 2\n");
      n--;
    } else {
      printf("1 2\n");
      n--;
      printf("1 2\n");
      n--;
      printf("%d %d\n", n-1, n);
      n--;
    }
    while (n > 1) {
      printf("1 %d\n", n);
      n--;
    }
  } else if (gcd((a[0]-1LL)*(a[1]-1LL), a[2]) != 1LL) {
    printf("0\n");
    printf("1 2\n");
    printf("1 2\n");
  } else if (gcd(a[0], a[2]) != 1LL || a[2] == 0LL || gcd((a[0]-1LL)*(a[2]-1LL), a[1]) != 1LL) {
    printf("0\n");
    printf("1 3\n");
    printf("1 2\n");
  } else if (gcd((a[1]-1LL)*(a[2]-1LL), a[0]) != 1LL) {
    printf("0\n");
    printf("2 3\n");
    printf("1 2\n");
  } else {
    long long max = 0LL;
    int argmax = 0;
    for (int i = 0; i < n; i++) {
      if (max < a[i]) {
        max = a[i];
        argmax = i;
      }
    }
    printf("%lld\n",(a[0]-1LL)*(a[1]-1LL)*(a[2]-1LL)-max+1LL);
    printf("%d %d\n", (argmax+1)%3+1, (argmax+2)%3+1);
    printf("1 2\n");
  }
  
  return 0;
}
0