結果
| 問題 |
No.688 E869120 and Constructing Array 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-03 13:30:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 855 bytes |
| コンパイル時間 | 1,561 ms |
| コンパイル使用メモリ | 167,832 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-11 20:55:53 |
| 合計ジャッジ時間 | 2,483 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:32:20: warning: 'ans1' may be used uninitialized [-Wmaybe-uninitialized]
32 | cout << ans1 + ans2 << endl;
| ^~~~
main.cpp:15:9: note: 'ans1' was declared here
15 | int ans1,ans2;
| ^~~~
main.cpp:32:20: warning: 'ans2' may be used uninitialized [-Wmaybe-uninitialized]
32 | cout << ans1 + ans2 << endl;
| ^~~~
main.cpp:15:14: note: 'ans2' was declared here
15 | int ans1,ans2;
| ^~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int main(){
ll k;
cin >> k;
int n = 30;
int ans1,ans2;
bool ok = false;
for(int i=1;i<=n;i++){
ll two = 1;
for(int b=0;b<=i;b++){
if(k%two != 0) break;
ll a = i - b;
if( ((a*(a-1))/2) * two == k){
ans1 = a;
ans2 = b;
ok = true;
}
two *= 2;
if(ok) break;
}
if(ok) break;
}
cout << ans1 + ans2 << endl;
rep(i,ans1) cout << 1 <<" ";
rep(i,ans2) cout << 0 << " ";
cout << endl;
return 0;
}