結果

問題 No.2756 GCD Teleporter
ユーザー 👑 chro_96chro_96
提出日時 2024-05-10 22:31:27
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 30,336 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-10 22:31:36
合計ジャッジ時間 7,838 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 15 ms
6,944 KB
testcase_05 AC 59 ms
6,944 KB
testcase_06 AC 168 ms
6,944 KB
testcase_07 AC 130 ms
6,944 KB
testcase_08 AC 118 ms
6,940 KB
testcase_09 AC 104 ms
6,944 KB
testcase_10 AC 150 ms
6,940 KB
testcase_11 AC 193 ms
6,944 KB
testcase_12 AC 40 ms
6,940 KB
testcase_13 AC 222 ms
6,940 KB
testcase_14 AC 186 ms
6,940 KB
testcase_15 AC 43 ms
6,940 KB
testcase_16 AC 101 ms
6,940 KB
testcase_17 AC 125 ms
6,940 KB
testcase_18 AC 39 ms
6,940 KB
testcase_19 AC 207 ms
6,944 KB
testcase_20 AC 225 ms
6,944 KB
testcase_21 AC 111 ms
6,940 KB
testcase_22 AC 169 ms
6,944 KB
testcase_23 AC 29 ms
6,944 KB
testcase_24 AC 174 ms
6,940 KB
testcase_25 AC 196 ms
6,940 KB
testcase_26 AC 193 ms
6,944 KB
testcase_27 AC 170 ms
6,940 KB
testcase_28 AC 95 ms
6,944 KB
testcase_29 AC 156 ms
6,940 KB
testcase_30 AC 184 ms
6,940 KB
testcase_31 AC 77 ms
6,940 KB
testcase_32 AC 270 ms
6,940 KB
testcase_33 AC 105 ms
6,940 KB
testcase_34 AC 22 ms
6,944 KB
testcase_35 AC 149 ms
6,940 KB
testcase_36 AC 99 ms
6,940 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 317 ms
6,940 KB
testcase_39 AC 264 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct tree {
  struct tree *p;
} tree;

tree *get_root (tree *t) {
  if (t == NULL || t->p == NULL) {
    return t;
  }
  
  t->p = get_root(t->p);
  return t->p;
}

int main () {
  int n = 0;
  int a = 0;
  
  int res = 0;
  
  int ans = 0;
  
  int cnt = 0;
  tree t[200000] = {};
  tree *tp[200001] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    t[i].p = NULL;
    res = scanf("%d", &a);
    tmp = a;
    for (int p = 2; p*p <= a; p++) {
      if (tmp%p == 0) {
        if (tp[p] != NULL) {
          tree *rt = get_root(tp[p]);
          if (rt != t+i) {
            rt->p = t+i;
            cnt++;
          }
        }
        tp[p] = t+i;
        while (tmp%p == 0) {
          tmp /= p;
        }
      }
    }
    if (tmp > 1) {
      if (tp[tmp] != NULL) {
        tree *rt = get_root(tp[tmp]);
        if (rt != t+i) {
          rt->p = t+i;
          cnt++;
        }
      }  
      tp[tmp] = t+i;
    }
  }
  
  if (tp[2] != NULL) {
    ans = (n-cnt-1)*2;
  } else if (tp[3] != NULL && cnt == n-2) {
    ans = 3;
  } else if (cnt < n-1) {
    ans = (n-cnt)*2;
  }
  
  printf("%d\n", ans);
  return 0;
}
0