結果

問題 No.2881 Mod 2^N
ユーザー tnakao0123tnakao0123
提出日時 2024-09-10 12:59:16
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 44,672 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-10 12:59:19
合計ジャッジ時間 2,317 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2881.cc:  No.2881 Mod 2^N - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 60;

/* typedef */

using ll = long long;

/* global variables */

int bs[MAX_N], as[MAX_N];

/* subroutines */

ll f(int i, int n, ll x) {
  return ((x << i) + 1) & ((1LL << n) - 1);
}

/* main */

int main() {
  int n;
  ll x, y;
  scanf("%d%lld%lld", &n, &x, &y);

  if (x == y) { puts("0"); return 0; }
  if (! (y & 1)) { puts("-1"); return 0; }

  int m = 0;
  for (int i = 0; i < n; i++)
    if ((y >> i) & 1) bs[m++] = i;

  int k = 0;
  as[k++] = n;
  x = f(n, n, x);

  for (int i = m - 2; i >= 0; i--) {
    int d = bs[i + 1] - bs[i];
    as[k++] = d;
    x = f(d, n, x);
  }

  printf("%d\n", k);
  for (int i = 0; i < k; i++)
    printf("%d%c", as[i], (i + 1 < k) ? ' ' : '\n');
  //printf(" x=%lld, y=%lld\n", x, y);
  
  return 0;
}
0