結果

問題 No.585 工夫のないパズル
ユーザー cielciel
提出日時 2017-10-29 21:00:50
言語 Ruby
(3.3.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-05-01 22:22:46
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
12,416 KB
testcase_01 AC 89 ms
12,416 KB
testcase_02 AC 90 ms
12,288 KB
testcase_03 AC 89 ms
12,160 KB
testcase_04 AC 91 ms
12,160 KB
testcase_05 AC 94 ms
12,160 KB
testcase_06 AC 88 ms
12,288 KB
testcase_07 AC 88 ms
12,160 KB
testcase_08 AC 88 ms
12,160 KB
testcase_09 AC 90 ms
12,160 KB
testcase_10 AC 88 ms
12,416 KB
testcase_11 AC 90 ms
12,160 KB
testcase_12 AC 97 ms
12,160 KB
testcase_13 AC 88 ms
12,416 KB
testcase_14 AC 88 ms
12,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:20: warning: assigned but unused variable - mse
Main.rb:36: warning: assigned but unused variable - sy0
Main.rb:37: warning: assigned but unused variable - sy1
Main.rb:40: warning: assigned but unused variable - sy
Syntax OK

ソースコード

diff #

R=[]
class Array
def rotR(r,n)
	R<<'R %d %d'%[r,n]
	a=self.dup;a[r]=a[r].rotate(-n);a
end
def rotD(c,n)
	R<<'C %d %d'%[c,n]
	a=self.transpose;a[c]=a[c].rotate(-n);a.transpose
end
def search(n)
	self.size.times{|y|self[y].size.times{|x|return [x,y] if self[y][x]==n}}
end
def sw(c)
	k=self.size-1;self.rotD(c,1).rotR(k,1).rotD(c,3).rotR(k,2).rotD(c,1).rotR(k,1).rotD(c,3).rotR(k,1)
end
end
m=$<.map{|e|e.chomp.chars.map{|c|c.ord-65}}
mss=(m.size-1)*m[0].size
mse=mss+m[0].size
mss.times{|i|
	sx,sy=m.search i
	ty,tx=i.divmod(m[0].size)
	if sx==tx
		next if sy==ty
		m=m.rotR sy,1
		sx=-~sx%m[0].size
	end
	if sy==ty
		m=m.rotD(sx,1).rotD(tx,1).rotR(sy+1,(tx-sx)%m[0].size).rotD(sx,m.size-1).rotD(tx,m.size-1)
	else
		m=m.rotD(tx,sy-ty).rotR(sy,(tx-sx)%m[0].size).rotD(tx,m[0].size-sy+ty)
	end
}
#以下の処理は4x4専用
sx0,sy0=m.search mss
sx1,sy1=m.search mss+1
(sx0-sx1)%4==1&&m=m.sw(sx0+1)
(sx0-sx1)%4==2&&m=m.sw(sx1+1)
sx,sy=m.search mss
sx!=0&&m=m.rotR(3,4-sx)
sx0,sy0=m.search mss+2
sx0!=2&&m.sw(0)
p R.size
puts R
0