Submission #2946353


Source Code Expand

Copy
N, M = gets.split.map(&:to_i)
MAX = 1000
edges = Array.new(MAX**2){[]}
(1...MAX).each do |i|
    (1...MAX).each do |j|
        i2, j2 = i, j
        code = i2*MAX+j2
        i2, j2 = j2, i2 if i2 > j2
        i2 = i2.to_s.reverse.to_i
        i2, j2 = j2, i2 if i2 > j2
        j2 -= i2
        code2 = i2*MAX+j2
        edges[code2].push(code)
    end
end

arr = Array.new(MAX**2, true)
stack = (0...MAX).map{|i|i*MAX} + (0...MAX).map{|i|i}
while stack.length > 0
    code = stack.pop
    arr[code] = false
    edges[code].each do |code2|
        stack.push(code2) if arr[code2]
    end
end

ans = 0
(1..N).each do |i|
    ans += arr[i*MAX+1, M].count{|e| e}
end
puts ans

Submission Info

Submission Time
Task D - うほょじご
User betrue12
Language Ruby (2.3.3)
Score 400
Code Size 702 Byte
Status
Exec Time 1174 ms
Memory 113532 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 1170 ms 113404 KB
02.txt 1129 ms 113532 KB
03.txt 1159 ms 113532 KB
04.txt 1132 ms 113532 KB
05.txt 1146 ms 113532 KB
06.txt 1154 ms 113532 KB
07.txt 1128 ms 113404 KB
08.txt 1174 ms 113532 KB
09.txt 1139 ms 113532 KB
10.txt 1159 ms 113404 KB
11.txt 1166 ms 113532 KB
12.txt 1129 ms 113532 KB
13.txt 1116 ms 113532 KB
14.txt 1170 ms 113404 KB
15.txt 1157 ms 113532 KB
16.txt 1149 ms 113532 KB
s1.txt 1144 ms 113532 KB
s2.txt 1140 ms 113404 KB
s3.txt 1168 ms 113404 KB