Submission #1307153


Source Code Expand

def sort(k)
	a=Array.new()
	k.each_char{|t|
		a.push(t)
	}
	a.sort!
	b=""
	a.each{|t|
		b+=t
	}
	return b
end

x=gets.chomp.split(" ")
n=x[0].to_i
k=x[1].to_i
s=gets.chomp
q=sort(s)
a=""
t=s.length

def remain(s,b)
	t=s
	c=b #tからcを外す
	c.each_char{|r|
		if t.index(r) then
			if t.index(r)>0 then
				k=t.index(r)
				t=t[0..k-1]+t[k+1..-1]
			else
				t=t[1..-1]
			end
		end
	}
	return t
end

def ispossible(a,l,s,k)
	a+l #これがないと動かない
	#aの末尾にlを足してsとの違いをk文字以内にできるか?
	b=a+l
	#p [s,b]
	c=remain(s,b) #並べ替えの残り文字列
	d=s[(a.length+1)..-1] #sの残り文字列
	#p [a,b,c,d]
	n=countdifference(s,b)
	if n>k then
		return false
	else #tmp
		if weakcountdifference(c,d)+n>k then
			return false
		else
			return true
		end
	end
end

def countdifference(s,t)
	p=t.length
	c=0
	for i in 0..p-1 do
		if s[i]!=t[i] then
			c+=1
		end
	end
	return c
end

def weakcountdifference(s,t)
	return remain(s,t).length
end

for i in 0..t-1 do #aの文字列を特定
	for j in 0..t-1 do #aのi文字目を特定
		if ispossible(a,q[j],s,k) then
			a+=q[j]
			if j==0 then
				q=q[1..-1]
			else
				q=q[0..j-1]+q[j+1..-1]
			end
			break
		end
	end
end
print a

Submission Info

Submission Time
Task C - 辞書式順序ふたたび
User itonayuta60
Language Ruby (2.3.3)
Score 0
Code Size 1318 Byte
Status WA
Exec Time 307 ms
Memory 1788 KB

Compile Error

./Main.rb:39: warning: possibly useless use of + in void context
./Main.rb:15: warning: assigned but unused variable - n
./Main.rb:73: warning: assigned but unused variable - i

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
WA × 58
Set Name Test Cases
All hand_1_0.txt, hand_1_1.txt, hand_1_2.txt, hand_1_3.txt, hand_1_4.txt, hand_1_5.txt, hand_1_6.txt, hand_1_7.txt, hand_1_8.txt, hand_2_0.txt, hand_2_1.txt, hand_2_10.txt, hand_2_2.txt, hand_2_3.txt, hand_2_4.txt, hand_2_5.txt, hand_2_6.txt, hand_2_7.txt, hand_2_8.txt, hand_2_9.txt, hand_3_2.txt, hand_3_3.txt, hand_3_4.txt, hand_3_5.txt, hand_3_6.txt, hand_4_2.txt, hand_4_3.txt, hand_4_4.txt, hand_4_5.txt, hand_4_6.txt, random_1.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, small_8.txt, small_9.txt
Case Name Status Exec Time Memory
hand_1_0.txt WA 7 ms 1788 KB
hand_1_1.txt WA 7 ms 1788 KB
hand_1_2.txt WA 7 ms 1788 KB
hand_1_3.txt WA 7 ms 1788 KB
hand_1_4.txt WA 7 ms 1788 KB
hand_1_5.txt WA 7 ms 1788 KB
hand_1_6.txt WA 7 ms 1788 KB
hand_1_7.txt WA 7 ms 1788 KB
hand_1_8.txt WA 7 ms 1788 KB
hand_2_0.txt WA 7 ms 1788 KB
hand_2_1.txt WA 8 ms 1788 KB
hand_2_10.txt WA 7 ms 1788 KB
hand_2_2.txt WA 8 ms 1788 KB
hand_2_3.txt WA 8 ms 1788 KB
hand_2_4.txt WA 7 ms 1788 KB
hand_2_5.txt WA 7 ms 1788 KB
hand_2_6.txt WA 7 ms 1788 KB
hand_2_7.txt WA 7 ms 1788 KB
hand_2_8.txt WA 7 ms 1788 KB
hand_2_9.txt WA 7 ms 1788 KB
hand_3_2.txt WA 8 ms 1788 KB
hand_3_3.txt WA 7 ms 1788 KB
hand_3_4.txt WA 7 ms 1788 KB
hand_3_5.txt WA 7 ms 1788 KB
hand_3_6.txt WA 7 ms 1788 KB
hand_4_2.txt WA 10 ms 1788 KB
hand_4_3.txt WA 10 ms 1788 KB
hand_4_4.txt WA 10 ms 1788 KB
hand_4_5.txt WA 9 ms 1788 KB
hand_4_6.txt WA 9 ms 1788 KB
random_1.txt WA 15 ms 1788 KB
random_10.txt WA 284 ms 1788 KB
random_11.txt WA 201 ms 1788 KB
random_12.txt WA 207 ms 1788 KB
random_13.txt WA 137 ms 1788 KB
random_14.txt WA 52 ms 1788 KB
random_15.txt WA 21 ms 1788 KB
random_2.txt WA 27 ms 1788 KB
random_3.txt WA 23 ms 1788 KB
random_4.txt WA 61 ms 1788 KB
random_5.txt WA 14 ms 1788 KB
random_6.txt WA 98 ms 1788 KB
random_7.txt WA 174 ms 1788 KB
random_8.txt WA 280 ms 1788 KB
random_9.txt WA 307 ms 1788 KB
sample_1.txt WA 7 ms 1788 KB
sample_2.txt WA 7 ms 1788 KB
sample_3.txt WA 7 ms 1788 KB
sample_4.txt WA 7 ms 1788 KB
small_1.txt WA 7 ms 1788 KB
small_2.txt WA 7 ms 1788 KB
small_3.txt WA 7 ms 1788 KB
small_4.txt WA 7 ms 1788 KB
small_5.txt WA 7 ms 1788 KB
small_6.txt WA 7 ms 1788 KB
small_7.txt WA 7 ms 1788 KB
small_8.txt WA 7 ms 1788 KB
small_9.txt WA 7 ms 1788 KB