結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー tails
提出日時 2019-09-02 19:03:55
言語 Perl
(5.40.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 569 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 7,072 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-06-24 06:38:12
合計ジャッジ時間 2,445 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Name "main::y" used only once: possible typo at Main.pl line 25.
Main.pl syntax OK

ソースコード

diff #

# almost beta-ishoku of
# https://yukicoder.me/submissions/374293 by nadare

$N=<>;
@DP = (999)x($N+1);
$DP[0] = 0;

$r=int sqrt$N;
for$i(0..$N-$r*$r){
	for$j(1..sqrt$N-$i){
		$f=$j*$j;
		$DP[$i+$f]=$DP[$i]+$j if $DP[$i+$f]>$DP[$i]+$j;
	}
}
for(0,1){
	$DP[$N]=$DP[$N-$r*$r]+$r if $DP[$N]>$DP[$N-$r*$r]+$r;
	--$r;
}

$x = $N;
$j=1;
while($x){
	$f=$j*$j;
	if($DP[$x] == $DP[$x-$f] + $j){
		$y=$j;
		if($j%2){
			print"01"x($j/2),0;
		}else{
			push@E,$j;
		}
		$x -= $f;
	}else{
		++$j;
	}
}

while($e=pop@E){
	print"01"x($e/2);
	if($e=shift@E){
		print"10"x($e/2);
	}
}
0