結果

問題 No.2236 Lights Out On Simple Graph
ユーザー 👑 chro_96chro_96
提出日時 2023-03-03 22:22:28
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,724 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 31,172 KB
実行使用メモリ 34,400 KB
最終ジャッジ日時 2023-10-18 02:32:35
合計ジャッジ時間 20,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
18,348 KB
testcase_01 AC 6 ms
18,284 KB
testcase_02 WA -
testcase_03 AC 464 ms
33,608 KB
testcase_04 AC 319 ms
22,160 KB
testcase_05 AC 6 ms
18,348 KB
testcase_06 AC 417 ms
26,256 KB
testcase_07 WA -
testcase_08 AC 6 ms
18,284 KB
testcase_09 WA -
testcase_10 AC 110 ms
22,136 KB
testcase_11 WA -
testcase_12 AC 163 ms
22,136 KB
testcase_13 AC 16 ms
18,772 KB
testcase_14 AC 343 ms
26,224 KB
testcase_15 AC 13 ms
18,508 KB
testcase_16 AC 21 ms
18,772 KB
testcase_17 AC 58 ms
20,092 KB
testcase_18 AC 7 ms
18,376 KB
testcase_19 AC 38 ms
19,036 KB
testcase_20 AC 227 ms
26,224 KB
testcase_21 AC 37 ms
19,036 KB
testcase_22 AC 463 ms
34,400 KB
testcase_23 AC 482 ms
26,256 KB
testcase_24 AC 379 ms
24,208 KB
testcase_25 AC 80 ms
20,092 KB
testcase_26 AC 463 ms
34,400 KB
testcase_27 AC 226 ms
26,224 KB
testcase_28 AC 359 ms
26,224 KB
testcase_29 AC 37 ms
19,300 KB
testcase_30 AC 459 ms
34,400 KB
testcase_31 AC 463 ms
34,400 KB
testcase_32 AC 455 ms
34,400 KB
testcase_33 AC 466 ms
33,608 KB
testcase_34 AC 459 ms
34,400 KB
testcase_35 AC 509 ms
34,400 KB
testcase_36 AC 607 ms
32,400 KB
testcase_37 AC 471 ms
34,400 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 297 ms
25,696 KB
testcase_41 AC 37 ms
19,300 KB
testcase_42 WA -
testcase_43 AC 16 ms
18,772 KB
testcase_44 AC 540 ms
34,400 KB
testcase_45 WA -
testcase_46 AC 457 ms
34,400 KB
testcase_47 AC 500 ms
34,400 KB
testcase_48 AC 471 ms
34,400 KB
testcase_49 AC 469 ms
34,400 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 7 ms
18,284 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int cmp_ll (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;
  int m = 0;
  long long a[40] = {};
  long long b[40] = {};
  long long c = 0LL;
  
  int res = 0;
  
  int ans = 0;
  
  long long cbit = 0LL;
  long long half[1048576][2] = {};
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    res = scanf("%lld", a+i);
    res = scanf("%lld", b+i);
    a[i] -= 1LL;
    b[i] -= 1LL;
  }
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", &c);
    cbit |= (c<<((long long)i));
  }
  
  ans = m+1;
  
  for (int i = 0; i < (1<<(m/2)); i++) {
    for (int j = 0; j < m/2; j++) {
      if ((i&(1<<j)) > 0) {
        half[i][1] += 1LL;
        half[i][0] ^= (1LL<<a[j]);
        half[i][0] ^= (1LL<<b[j]);
      }
    }
  }
  
  qsort(half, (1<<(m/2)), sizeof(long long)*2, cmp_ll);
  
  for (int i = 0; i < (1<<(m-m/2)); i++) {
    long long hbit = 0LL;
    int cnt = 0;
    int idx[2] = { 0, (1<<m/2) };
    for (int j = 0; j < m-m/2; j++) {
      if ((i&(1<<j)) > 0) {
        cnt++;
        hbit ^= (1LL<<a[j+m/2]);
        hbit ^= (1LL<<b[j+m/2]);
      }
    }
    while (idx[1] - idx[0] > 1) {
      int nxt = (idx[0]+idx[1])/2;
      if (half[nxt][0] <= (cbit^hbit)) {
        idx[0] = nxt;
      } else {
        idx[1] = nxt;
      }
    }
    if (half[idx[0]][0] == (cbit^hbit) && ans > cnt+((int)half[idx[0]][1])) {
      ans = cnt+((int)half[idx[0]][1]);
    }
  }
  
  if (ans > m) {
    printf("-1\n");
    return 0;
  }
  
  printf("%d\n", ans);
  return 0;
}
0