結果

問題 No.382 シャイな人たち (2)
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2020-04-26 10:14:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,231 ms / 8,000 ms
コード長 1,427 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 33,828 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 01:55:37
合計ジャッジ時間 23,295 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,230 ms
4,384 KB
testcase_01 AC 1,231 ms
4,380 KB
testcase_02 AC 1,042 ms
4,376 KB
testcase_03 AC 1,028 ms
4,376 KB
testcase_04 AC 996 ms
4,380 KB
testcase_05 AC 1,097 ms
4,380 KB
testcase_06 AC 809 ms
4,380 KB
testcase_07 AC 1,136 ms
4,376 KB
testcase_08 AC 855 ms
4,376 KB
testcase_09 AC 958 ms
4,376 KB
testcase_10 AC 949 ms
4,380 KB
testcase_11 AC 831 ms
4,380 KB
testcase_12 AC 1,037 ms
4,384 KB
testcase_13 AC 1,046 ms
4,376 KB
testcase_14 AC 1,125 ms
4,380 KB
testcase_15 AC 1,144 ms
4,376 KB
testcase_16 AC 928 ms
4,376 KB
testcase_17 AC 873 ms
4,376 KB
testcase_18 AC 1,070 ms
4,380 KB
testcase_19 AC 958 ms
4,376 KB
testcase_20 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>

using u32 = unsigned;
using u64 = unsigned long long;
using u128 = __uint128_t;

u32 step(u32 s){
  return (u64) s * 12345 % 1000003;
}

u128 edges[121];

int ctz(const u128 &n){
  if((u64) n){
    return __builtin_ctzll((u64) n);
  }
  return 64 + __builtin_ctzll((u64) (n >> 64));
}

int popc(const u128 &n){
  return __builtin_popcountll((u64) n) + __builtin_popcountll((u64) (n >> 64));
}

u128 mis(const u128 &g){
  if(g == 0) return 0;
  int y = 127;
  int d = 0;
  for(u128 h = g; h; h &= h - 1){
    int z = ctz(h);
    int k = popc(g & edges[z]);
    if(k <= 2) return mis(g & ~edges[z]) | ((u128) 1 << z);
    if(k > d){
      y = z;
      d = k;
    }
  }

  u128 g0 = mis(g & ~edges[y]) | ((u128) 1 << y);

  if(d == 3) return g0;

  u128 g1 = mis(g & ~((u128) 1 << y));

  return popc(g0) > popc(g1) ? g0 : g1;
}



int main(){
  int s;
  scanf("%d", &s);
  s = step(s);
  int n = (s % 120) + 2;
  s = step(s);
  int p = s;
  for(int i = 0; i < n; i++){
    edges[i] |= ((u128) 1 << i);
    for(int j = i+1; j < n; j++){
      s = step(s);
      edges[i] |= ((u128) (s >= p) << j);
      edges[j] |= ((u128) (s >= p) << i);
    }
  }
  u128 g = mis(((u128) 1 << n) - 1);
  int smis = popc(g);
  if(smis == n){
    puts("-1");
    return 0;
  }
  printf("%d\n", popc(g)+1);
  for(u128 h = g; h; ){
    printf("%d", ctz(h) + 1);
    h &= h - 1;
    printf("%c", h ? ' ' : '\n');
  }
  return 0;
}
0