結果

問題 No.2114 01 Matching
ユーザー 👑 chro_96chro_96
提出日時 2022-10-28 23:44:53
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,667 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 29,884 KB
実行使用メモリ 6,536 KB
最終ジャッジ日時 2023-09-20 07:05:06
合計ジャッジ時間 8,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,968 KB
testcase_02 AC 123 ms
6,528 KB
testcase_03 AC 25 ms
5,044 KB
testcase_04 AC 35 ms
5,248 KB
testcase_05 WA -
testcase_06 AC 124 ms
6,336 KB
testcase_07 AC 124 ms
6,520 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 124 ms
6,404 KB
testcase_11 AC 116 ms
6,336 KB
testcase_12 AC 116 ms
6,464 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 123 ms
6,404 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 116 ms
6,524 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 115 ms
6,520 KB
testcase_27 AC 115 ms
6,448 KB
testcase_28 AC 63 ms
5,636 KB
testcase_29 AC 115 ms
6,532 KB
testcase_30 AC 124 ms
6,404 KB
testcase_31 AC 115 ms
6,520 KB
testcase_32 WA -
testcase_33 AC 123 ms
6,332 KB
testcase_34 AC 96 ms
6,144 KB
testcase_35 AC 47 ms
5,624 KB
testcase_36 AC 115 ms
6,332 KB
testcase_37 WA -
testcase_38 AC 126 ms
6,496 KB
testcase_39 WA -
testcase_40 AC 46 ms
5,512 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 124 ms
6,496 KB
testcase_44 WA -
testcase_45 AC 79 ms
6,536 KB
testcase_46 WA -
testcase_47 AC 116 ms
6,400 KB
testcase_48 AC 116 ms
6,376 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 123 ms
6,456 KB
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int cmp_int_3d (const void *a, const void *b) {
  int *a_ = (int *)a;
  int *b_ = (int *)b;
  int idx = 0;
  
  while (idx < 3) {
    if (a_[idx] < b_[idx]) {
      return -1;
    }
    if (a_[idx] > b_[idx]) {
      return 1;
    }
    idx++;
  }
  
  return 0;
}

int main () {
  int n = 0;
  int m = 0;
  int k = 0;
  int b[400000] = {};
  int r[400000] = {};
  
  int res = 0;
  
  int *bs = NULL;
  int *rs = NULL;
  
  long long ans = 0LL;
  int bidx = 0;
  int ridx = 0;
  int is_ok = 1;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  res = scanf("%d", &k);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", b+(2*i));
    b[2*i+1] = b[2*i]/k;
    b[2*i] %= k;
  }
  for (int i = 0; i < m; i++) {
    res = scanf("%d", r+(2*i));
    r[2*i+1] = r[2*i]/k;
    r[2*i] %= k;
  }
  
  if (m < n) {
    int tmp = m;
    m = n;
    n = tmp;
    bs = r;
    rs = b;
  } else {
    bs = b;
    rs = r;
  }
  
  qsort(bs, n, sizeof(int)*2, cmp_int_3d);
  qsort(rs, m, sizeof(int)*2, cmp_int_3d);
 
  while (bidx < n && is_ok > 0) {
    while (ridx < m && rs[2*ridx] < bs[2*bidx]) {
      ridx++;
    }
    if (ridx >= m || rs[2*ridx] > bs[2*bidx]) {
      is_ok = 0;
    } else {
      int bnidx = bidx;
      int rnidx = ridx;
      while (bnidx < n && bs[2*bidx] == bs[2*bnidx]) {
        bnidx++;
      }
      while (rnidx < m && rs[2*ridx] == rs[2*rnidx]) {
        rnidx++;
      }
      if (rnidx-ridx < bnidx-bidx) {
        is_ok = 0;
      } else {
      }
      bidx = bnidx;
      ridx = rnidx;
    } 
  }
  
  if (is_ok > 0) {
    printf("%lld\n", ans);
  } else {
    printf("-1\n");
  }
  
  return 0;
}
0