結果

問題 No.688 E869120 and Constructing Array 2
コンテスト
ユーザー amtgjw
提出日時 2018-05-22 16:38:21
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 744 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 507 ms
コンパイル使用メモリ 96,572 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2026-03-29 04:45:53
合計ジャッジ時間 3,803 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other WA * 9 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:45:21: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
   45 |         cout << (a+b) << endl;
      |                     ^
main.cpp:35:13: note: 'b' was declared here
   35 |         int b;
      |             ^

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <complex>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

#define INF 		2000000007
#define MOD			1000000007

#define MAX 		200005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

int dp[MAX];

int main(){
	int K;cin>>K;

	int a=1,N=K;
	while(K%2==0){
		K/=2;
		a++;
	}

	int b;
	while(K<N){
		double t = sqrt(1+8*K);
		if(ceil(t) == floor(t)){
			b = (t+1)/2;
			break;
		}
		K*=2;
		--a;
	}
	cout << (a+b) << endl;
	REP(i,a) cout << 0 << " ";
	REP(i,b) cout << 1 << " ";
	cout << endl;

	return 0;
}
0