Submission #21743445
Source Code Expand
Copy
A,B,S = $<.map{|ln| ln.chomp.bytes.reverse }C2D = [nil]*123D2C = [nil]*10NZ = [-1]*123; NZ[A[-1]] = NZ[B[-1]] = NZ[S[-1]] = 0Z = [A,B,S].map(&:size).maxF = lambda{|i,carry|next carry<1 if i==Za = (c = A[i]) ? C2D[c] : 0b = (c = B[i]) ? C2D[c] : 0 if anext D2C.each_with_index.find{|e,d|next if enext if d==NZ[c]D2C[d],C2D[c] = c,dnext F[i,carry] || D2C[d] = C2D[c] = nil} unless bsum = a+b+carryif s = (c = S[i]) ? C2D[c] : 0next s==sum%10 && F[i+1,sum/10]
A,B,S = $<.map{|ln| ln.chomp.bytes.reverse } C2D = [nil]*123 D2C = [nil]*10 NZ = [-1]*123; NZ[A[-1]] = NZ[B[-1]] = NZ[S[-1]] = 0 Z = [A,B,S].map(&:size).max F = lambda{|i,carry| next carry<1 if i==Z a = (c = A[i]) ? C2D[c] : 0 b = (c = B[i]) ? C2D[c] : 0 if a next D2C.each_with_index.find{|e,d| next if e next if d==NZ[c] D2C[d],C2D[c] = c,d next F[i,carry] || D2C[d] = C2D[c] = nil } unless b sum = a+b+carry if s = (c = S[i]) ? C2D[c] : 0 next s==sum%10 && F[i+1,sum/10] else s = sum%10 next if D2C[s] || s==NZ[c] D2C[s],C2D[c] = c,s next F[i+1,sum/10] || D2C[s] = C2D[c] = nil end } if (A|B|S).size<11 && F[0,0] puts [A,B,S].map{ _1.reverse_each.map{|c| C2D[c] }*'' } else puts'UNSOLVABLE' end
Submission Info
Submission Time | |
---|---|
Task | D - Send More Money |
User | ds14050 |
Language | Ruby (2.7.1) |
Score | 400 |
Code Size | 765 Byte |
Status | AC |
Exec Time | 66 ms |
Memory | 14412 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
All | hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
hand_01.txt | AC | 63 ms | 14012 KB |
hand_02.txt | AC | 63 ms | 14016 KB |
hand_03.txt | AC | 59 ms | 14236 KB |
hand_04.txt | AC | 62 ms | 14156 KB |
hand_05.txt | AC | 61 ms | 14104 KB |
random_01.txt | AC | 66 ms | 14088 KB |
random_02.txt | AC | 61 ms | 14244 KB |
random_03.txt | AC | 62 ms | 14076 KB |
random_04.txt | AC | 63 ms | 14100 KB |
random_05.txt | AC | 62 ms | 14132 KB |
random_06.txt | AC | 64 ms | 14412 KB |
random_07.txt | AC | 60 ms | 14104 KB |
random_08.txt | AC | 65 ms | 14344 KB |
random_09.txt | AC | 64 ms | 14060 KB |
random_10.txt | AC | 62 ms | 14264 KB |
random_11.txt | AC | 62 ms | 14236 KB |
random_12.txt | AC | 62 ms | 14280 KB |
random_13.txt | AC | 62 ms | 14076 KB |
random_14.txt | AC | 65 ms | 14156 KB |
random_15.txt | AC | 54 ms | 14260 KB |
random_16.txt | AC | 57 ms | 14148 KB |
random_17.txt | AC | 58 ms | 14216 KB |
random_18.txt | AC | 61 ms | 14008 KB |
random_19.txt | AC | 62 ms | 14144 KB |
random_20.txt | AC | 57 ms | 14156 KB |
random_21.txt | AC | 63 ms | 14132 KB |
random_22.txt | AC | 62 ms | 14056 KB |
random_23.txt | AC | 60 ms | 14136 KB |
random_24.txt | AC | 56 ms | 14136 KB |
random_25.txt | AC | 66 ms | 14084 KB |
random_26.txt | AC | 59 ms | 13964 KB |
random_27.txt | AC | 57 ms | 14128 KB |
random_28.txt | AC | 61 ms | 14168 KB |
random_29.txt | AC | 60 ms | 14168 KB |
random_30.txt | AC | 63 ms | 14064 KB |
sample_01.txt | AC | 64 ms | 14076 KB |
sample_02.txt | AC | 60 ms | 14328 KB |
sample_03.txt | AC | 59 ms | 14120 KB |
sample_04.txt | AC | 62 ms | 14288 KB |
sample_05.txt | AC | 64 ms | 14192 KB |