結果
問題 |
No.1871 divisXor
|
ユーザー |
![]() |
提出日時 | 2022-03-17 20:07:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 883 bytes |
コンパイル時間 | 330 ms |
コンパイル使用メモリ | 41,796 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 19:07:18 |
合計ジャッジ時間 | 3,159 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
/* -*- coding: utf-8 -*- * * 1871.cc: No.1871 divisXor - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int BN = 40; const int MAX_M = 100; /* typedef */ typedef long long ll; /* global variables */ ll as[MAX_M]; /* subroutines */ inline ll f(int k) { return (1LL << (k + 1)) - 1; } /* main */ int main() { ll n; scanf("%lld", &n); int m = 0; ll bi = 1, fsum = 0; for (int i = 0; i < BN; i++, bi <<= 1) if ((n & bi) != 0) { if (i > 0) { ll pa = 1LL << (i - 1); if (m > 0 && as[m - 1] == pa) m--; else as[m++] = pa; fsum ^= f(i - 1); } as[m++] = (1LL << i); fsum ^= f(i); } if (m == 0) puts("-1"); else { printf("%d\n", m); for (int i = 0; i < m; i++) printf("%lld%c", as[i], (i + 1 < m) ? ' ' : '\n'); } //printf("fsum=%lld\n", fsum); return 0; }