結果

問題 No.2094 Symmetry
ユーザー 👑 chro_96chro_96
提出日時 2022-10-07 21:58:45
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,348 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 30,292 KB
実行使用メモリ 8,788 KB
最終ジャッジ日時 2023-09-03 02:02:40
合計ジャッジ時間 5,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,924 KB
testcase_01 AC 2 ms
6,900 KB
testcase_02 AC 3 ms
7,032 KB
testcase_03 AC 3 ms
6,912 KB
testcase_04 AC 3 ms
6,992 KB
testcase_05 AC 2 ms
6,908 KB
testcase_06 AC 3 ms
6,848 KB
testcase_07 AC 3 ms
6,932 KB
testcase_08 AC 3 ms
6,936 KB
testcase_09 AC 92 ms
8,600 KB
testcase_10 AC 92 ms
8,716 KB
testcase_11 AC 93 ms
8,616 KB
testcase_12 AC 93 ms
8,652 KB
testcase_13 AC 92 ms
8,704 KB
testcase_14 AC 92 ms
8,716 KB
testcase_15 AC 92 ms
8,532 KB
testcase_16 AC 93 ms
8,532 KB
testcase_17 AC 93 ms
8,788 KB
testcase_18 AC 91 ms
8,636 KB
testcase_19 AC 92 ms
8,588 KB
testcase_20 AC 93 ms
8,708 KB
testcase_21 AC 91 ms
8,568 KB
testcase_22 AC 92 ms
8,532 KB
testcase_23 AC 93 ms
8,600 KB
testcase_24 AC 93 ms
8,708 KB
testcase_25 AC 93 ms
8,724 KB
testcase_26 AC 93 ms
8,700 KB
testcase_27 AC 3 ms
6,908 KB
testcase_28 AC 50 ms
7,640 KB
testcase_29 AC 3 ms
6,964 KB
testcase_30 AC 52 ms
7,604 KB
testcase_31 AC 51 ms
7,476 KB
testcase_32 AC 52 ms
7,540 KB
testcase_33 AC 4 ms
6,948 KB
testcase_34 AC 46 ms
8,192 KB
testcase_35 AC 44 ms
8,180 KB
testcase_36 AC 48 ms
8,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int cmp_ll_rev (const void *ap, const void *bp) {
  long long a = *(long long *)ap;
  long long b = *(long long *)bp;
  
  if (a < b) {
    return 1;
  }
  
  if (a > b) {
    return -1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  long long k = 0LL;
  char s[500][501] = {};
  long long c[500][500] = {};

  int res = 0;
  
  int bcnt = 0;
  long long c_sort[250000] = {};
  long long cp_sort[125000] = {};
  
  long long ans = 0LL;
  
  res = scanf("%d", &n);
  res = scanf("%lld", &k);
  for (int i = 0; i < 2*n; i++) {
    res = scanf("%s", s[i]);
  }
  for (int i = 0; i < 2*n; i++) {
    for (int j = 0; j < 2*n; j++) {
      res = scanf("%lld", c[i]+j);
      c_sort[2*n*i+j] = c[i][j];
      if (j >= n) {
        cp_sort[n*i+j-n] = c[i][j]+c[i][2*n-j-1];
      }
    }
  }
  
  for (int i = 0; i < 2*n; i++) {
    for (int j = 0; j < 2*n; j++) {
      if (s[i][j] == '#') {
        bcnt++;
      }
    }
  }
  
  qsort(c_sort, 4*n*n, sizeof(long long), cmp_ll_rev);
  qsort(cp_sort, 2*n*n, sizeof(long long), cmp_ll_rev);
  
  for (int i = 0; i < bcnt; i++) {
    ans += c_sort[i];
  }
  
  if (bcnt%2 == 0) {
    long long tmp = k;
    for (int i = 0; i < bcnt/2; i++) {
      tmp += cp_sort[i];
    }
    if (tmp > ans) {
      ans = tmp;
    }
  }
  
  printf("%lld\n", ans);
  return 0;
}
0