結果

問題 No.382 シャイな人たち (2)
ユーザー Min_25Min_25
提出日時 2016-06-19 10:52:51
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,414 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 77,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 12:59:38
合計ジャッジ時間 32,349 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,443 ms
5,248 KB
testcase_01 AC 1,457 ms
5,376 KB
testcase_02 AC 1,461 ms
5,376 KB
testcase_03 AC 1,472 ms
5,376 KB
testcase_04 AC 1,460 ms
5,376 KB
testcase_05 AC 1,488 ms
5,376 KB
testcase_06 AC 1,417 ms
5,376 KB
testcase_07 AC 1,440 ms
5,376 KB
testcase_08 AC 1,434 ms
5,376 KB
testcase_09 AC 1,513 ms
5,376 KB
testcase_10 AC 1,456 ms
5,376 KB
testcase_11 AC 1,355 ms
5,376 KB
testcase_12 AC 1,503 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 1,482 ms
5,376 KB
testcase_15 AC 1,515 ms
5,376 KB
testcase_16 AC 1,459 ms
5,376 KB
testcase_17 AC 1,544 ms
5,376 KB
testcase_18 AC 1,461 ms
5,376 KB
testcase_19 AC 1,450 ms
5,376 KB
testcase_20 AC 38 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <tuple>

#define _fetch(_1, _2, _3, _4, name, ...) name
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c))
#define rep(...) _fetch(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__)

using namespace std;

using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f80 = long double;
using u128 = __uint128_t;

const u32 N_MAX = 120;
u128 edges[N_MAX + 1];
u128 bits[N_MAX + 1];

struct Rand {
  Rand(u32 seed) : x(seed) {}
  u32 next() { return x = u64(x) * 12345 % 1000003; }
  u32 x;
};

int gene_graph(int S) {
  auto gene = Rand(S);
  int N = gene.next() % N_MAX + 2;
  int P = gene.next();
  rep(i, N) edges[i] = bits[i];
  rep(i, N) rep(j, i + 1, N) {
    int X = gene.next();
    if (X >= P) {
      edges[i] |= u128(1) << j;
      edges[j] |= u128(1) << i;
    }
  }
  return N;
}

struct xor64 {
  xor64(u64 seed) : x(seed) {}
  u64 next() {
    x ^= x << 13; x ^= x >> 7;
    return x ^= x << 17;
  }
  u64 x;
};

vector<int> rmis(int N) {
  int perms[N_MAX + 1];
  int ret[N_MAX + 1], t[N_MAX + 1];
  int max_c = 0;

  auto gene = xor64(rand());
  const auto G = (u128(1) << N) - 1;

  rep(i, N) perms[i] = i;
  rep(_, 1000000) {
    u128 V = 0;
    int c = 0;
    for (int i = N - 1; i >= 0; --i) {
      swap(perms[gene.next() % (i + 1)], perms[i]);
      int v = perms[i];
      if (V & bits[v]) continue;
      V |= edges[v];
      t[c++] = v;
      if (V == G) break;
    }
    if (c > max_c) {
      max_c = c;
      copy(t, t + c, ret);
    }
  }
  return vector<int>(ret, ret + max_c);
}

void solve() {
  srand(time(nullptr));
  bits[0] = 1;
  rep(i, 1, N_MAX + 1) bits[i] = bits[i - 1] << 1;

  int S;
  while (~scanf("%d", &S)) {
    int N = gene_graph(S);
    auto ans = rmis(N);
    if (int(ans.size()) == N) {
      puts("-1");
    } else {
      printf("%u\n", int(ans.size() + 1));
      printf("%u", ans[0] + 1);
      rep(i, 1, ans.size()) printf(" %u", ans[i] + 1);
      puts("");
    }
  }
}

int main() {
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
0