結果

問題 No.2718 Best Consonance
ユーザー 👑 chro_96chro_96
提出日時 2024-04-05 23:11:11
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,287 ms / 4,000 ms
コード長 1,372 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 9,704 KB
最終ジャッジ日時 2024-04-10 10:54:28
合計ジャッジ時間 18,627 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 739 ms
9,384 KB
testcase_15 AC 560 ms
8,720 KB
testcase_16 AC 606 ms
8,816 KB
testcase_17 AC 480 ms
8,172 KB
testcase_18 AC 655 ms
9,040 KB
testcase_19 AC 540 ms
8,424 KB
testcase_20 AC 746 ms
9,196 KB
testcase_21 AC 706 ms
9,188 KB
testcase_22 AC 715 ms
9,324 KB
testcase_23 AC 428 ms
8,088 KB
testcase_24 AC 777 ms
9,580 KB
testcase_25 AC 775 ms
9,544 KB
testcase_26 AC 774 ms
9,456 KB
testcase_27 AC 770 ms
9,624 KB
testcase_28 AC 770 ms
9,704 KB
testcase_29 AC 768 ms
9,488 KB
testcase_30 AC 769 ms
9,520 KB
testcase_31 AC 771 ms
9,448 KB
testcase_32 AC 777 ms
9,548 KB
testcase_33 AC 767 ms
9,472 KB
testcase_34 AC 4 ms
6,944 KB
testcase_35 AC 3 ms
6,940 KB
testcase_36 AC 1,105 ms
7,908 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 1,287 ms
8,040 KB
testcase_39 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

#define INF 1000000000000LL

int cmp_mul_rev (const void *a, const void *b) {
  long long *a_ = (long long *)a;
  long long *b_ = (long long *)b;
  
  if (a_[0]*a_[1] < b_[0]*b_[1]) {
    return 1;
  }
  
  if (a_[0]*a_[1] > b_[0]*b_[1]) {
    return -1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  long long ab[200000][2] = {};
  
  int res = 0;
  
  long long ans = 0LL;
  long long min[200001] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", ab[i]);
    res = scanf("%lld", ab[i]+1);
  }
  
  qsort(ab, n, sizeof(long long)*2, cmp_mul_rev);
  
  for (int i = 0; i <= 200000; i++) {
    min[i] = INF;
  }
  
  for (int i = 0; i < n; i++) {
    long long mul = ab[i][0]*ab[i][1];
    for (long long p = 1LL; p*p <= ab[i][0]; p += 1LL) {
      if (ab[i][0]%p == 0LL) {
        if (mul/(min[(int)p]*ab[i][0]) > ans) {
          ans = mul/(min[(int)p]*ab[i][0]);
        }
        if (min[(int)p] > ab[i][0]/p) {
          min[(int)p] = ab[i][0]/p;
        }
        if (p*p != ab[i][0]) {
          if (mul/(min[(int)(ab[i][0]/p)]*ab[i][0]) > ans) {
            ans = mul/(min[(int)(ab[i][0]/p)]*ab[i][0]);
          }
          if (min[(int)(ab[i][0]/p)] > p) {
            min[(int)(ab[i][0]/p)] = p;
          }
        }
      }
    }
  }
  
  printf("%lld\n", ans);
  return 0;
}
0