結果

問題 No.382 シャイな人たち (2)
ユーザー Min_25Min_25
提出日時 2016-06-19 06:00:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,413 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 77,024 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 12:56:27
合計ジャッジ時間 6,113 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 142 ms
5,376 KB
testcase_03 AC 145 ms
5,376 KB
testcase_04 AC 141 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 140 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 154 ms
5,376 KB
testcase_10 AC 146 ms
5,376 KB
testcase_11 AC 138 ms
5,376 KB
testcase_12 AC 150 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 151 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 146 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 6 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(_, 100000) {
    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