結果
問題 | No.2881 Mod 2^N |
ユーザー |
![]() |
提出日時 | 2024-11-11 22:57:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,119 bytes |
コンパイル時間 | 2,011 ms |
コンパイル使用メモリ | 195,532 KB |
最終ジャッジ日時 | 2025-02-25 03:56:38 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/modint> using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* Xを1に初期化 あとはYと一致するように左シフト+1 X=YならYes Yの末尾のbitが1でないならNo */ ll N, X, Y, Z; cin >> N >> X >> Y; Z = X; if (X == Y){ cout << 0 << endl; cout << endl; return 0; } if (Y % 2 == 0){ cout << -1 << endl; return 0; } vector<ll> ans; //1に初期化 X = 1; ans.push_back(N); ll p=-1, z; for (int i=N-1; i>=0; i--){ if ((Y>>i) & 1){ if (p == -1) p = i; else{ z = p-i; ans.push_back(z); p = i; } } } for (auto x : ans){ Z = (Z<<x)+1; Z %= (1LL<<N); } assert(Z == Y); cout << ans.size() << endl; for (auto x : ans) cout << x << " "; cout << endl; return 0; }