結果
| 問題 |
No.2881 Mod 2^N
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-09-10 12:59:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 915 bytes |
| コンパイル時間 | 439 ms |
| コンパイル使用メモリ | 41,088 KB |
| 最終ジャッジ日時 | 2025-02-24 06:30:28 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d%lld%lld", &n, &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- 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;
}
tnakao0123