結果

問題 No.318 学学学学学
ユーザー koyumeishi
提出日時 2015-12-11 02:19:00
言語 Ruby
(3.4.1)
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 1,692 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 29,492 KB
最終ジャッジ日時 2024-06-22 15:16:02
合計ジャッジ時間 14,053 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#coding = utf-8
require "set"

💩 = gets.to_i;
💩💩 = gets.split().map(&:to_i);

💩💩💩💩 = 💩💩.sort().uniq()

👾 = 💩💩💩💩.size;

for 🚽 in 0...💩 do
	👇 = -1;
	👆 = 👾-1;
	while (👆-👇>1) do
		💪 = (👇+👆)/2;
		if 💩💩[🚽] <= 💩💩💩💩[💪] then
			👆 = 💪;
		else
			👇 = 💪;
		end
	end
	💩💩[🚽] = 👆;
end

🐕💩 = Array.new(👾);
🐈💩 = Array.new(👾);

0.upto(💩-1) { |🚽|
	🐕💩[ 💩💩[🚽] ] = 🚽;
}

(💩-1).downto(0) { |🚽|
	🐈💩[ 💩💩[🚽] ] = 🚽;
}

$👉💩 = Array.new(👾+5, 0);
$💩👈 = 👾;
def うんこ(🐦💩,x)
	🐦💩+=1;
	while(🐦💩<=$💩👈) do
		$👉💩[🐦💩] += x;
		🐦💩 += 🐦💩&-🐦💩;
	end
end

def 💩_bound(💩💩💩💩💩)
	if (💩💩💩💩💩<=0) then
		return 0;
	end
	___💩💩💩 = 0;
	_____💩💩💩 = 1;
	while (_____💩💩💩<<1) <= $💩👈 do
		_____💩💩💩<<=1;
	end
	while _____💩💩💩>0 do
		if(___💩💩💩+_____💩💩💩<=$💩👈 && $👉💩[___💩💩💩+_____💩💩💩] < 💩💩💩💩💩) then
			💩💩💩💩💩 -= $👉💩[___💩💩💩+_____💩💩💩];
			___💩💩💩 += _____💩💩💩;
		end
		_____💩💩💩 >>= 1;
	end
	return ___💩💩💩+1;
end

🎅 = Array.new(💩, "🎅");
contain_💩 = 0;

0.upto(💩-1) { |🚽|
	if 🐈💩[ 💩💩[🚽] ] == 🚽 then
		うんこ(💩💩[🚽], 1);
		contain_💩 += 1;
	end
	
	🎅[🚽] = 💩💩💩💩[💩_bound(contain_💩)-1];
	
	if 🐕💩[ 💩💩[🚽] ] == 🚽 then
		うんこ(💩💩[🚽], -1);
		contain_💩 -= 1;
	end
}


puts 🎅.join(" ")
0