Submission #3187988


Source Code Expand

n,m,d = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Array.new(n+1){|i|i}
ans = Array.new(n+1,0)
for i in 0..m-1
  b[a[i],2] = b[a[i]+1],b[a[i]]
end
c = Array.new(n+1,0)
for i in 1..n
  c[b[i]] = i
end
v = Array.new(n+1,false)
for i in 1..n
  next if v[i]
  t = [i]
  v[i] = true
  while t[0] != c[t[-1]]
    t << c[t[-1]]
    v[t[-1]] = true
  end
  for j in 0..t.size-1
    ans[t[j]] = t[(d+j)%t.size]
  end
end
puts ans[1..n]

Submission Info

Submission Time
Task D - 阿弥陀
User koikotya
Language Ruby (2.3.3)
Score 100
Code Size 461 Byte
Status AC
Exec Time 264 ms
Memory 24340 KB

Judge Result

Set Name Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 10 / 10 20 / 20 20 / 20 50 / 50
Status
AC × 9
AC × 18
AC × 18
AC × 29
Set Name Test Cases
Subtask1 sample_1.txt, 01_i.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt
Subtask2 sample_1.txt, sample_2.txt, sample_3.txt, 02_i.txt, 02_p.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_rp01.txt, 02_rp02.txt, 02_rp03.txt, 02_rp04.txt, 02_rp05.txt
Subtask3 sample_1.txt, sample_2.txt, 03_i.txt, 03_random01.txt, 03_random02.txt, 03_random03.txt, 03_random04.txt, 03_random05.txt, 03_random06.txt, 03_random07.txt, 03_random08.txt, 03_random09.txt, 03_random10.txt, 03_random11.txt, 03_random12.txt, 03_random13.txt, 03_random14.txt, 03_random15.txt
Subtask4 sample_1.txt, sample_2.txt, sample_3.txt, 04_i.txt, 04_p1.txt, 04_p2.txt, 04_random01.txt, 04_random02.txt, 04_random03.txt, 04_random04.txt, 04_random05.txt, 04_random06.txt, 04_random07.txt, 04_random08.txt, 04_random09.txt, 04_random10.txt, 04_random11.txt, 04_random12.txt, 04_random13.txt, 04_rp01.txt, 04_rp02.txt, 04_rp03.txt, 04_rp04.txt, 04_rp05.txt, 04_rp06.txt, 04_rp07.txt, 04_rp08.txt, 04_rp09.txt, 04_rp10.txt
Case Name Status Exec Time Memory
01_i.txt AC 263 ms 22804 KB
01_random01.txt AC 7 ms 1788 KB
01_random02.txt AC 7 ms 1788 KB
01_random03.txt AC 7 ms 1788 KB
01_random04.txt AC 17 ms 2428 KB
01_random05.txt AC 159 ms 7932 KB
01_random06.txt AC 229 ms 22444 KB
01_random07.txt AC 259 ms 24212 KB
02_i.txt AC 10 ms 1916 KB
02_p.txt AC 9 ms 1788 KB
02_random01.txt AC 7 ms 1788 KB
02_random02.txt AC 7 ms 1788 KB
02_random03.txt AC 10 ms 2172 KB
02_random04.txt AC 8 ms 1788 KB
02_random05.txt AC 21 ms 3580 KB
02_random06.txt AC 67 ms 10516 KB
02_random07.txt AC 130 ms 18708 KB
02_random08.txt AC 130 ms 18708 KB
02_rp01.txt AC 9 ms 1788 KB
02_rp02.txt AC 9 ms 1916 KB
02_rp03.txt AC 9 ms 1788 KB
02_rp04.txt AC 9 ms 1788 KB
02_rp05.txt AC 9 ms 3836 KB
03_i.txt AC 7 ms 1788 KB
03_random01.txt AC 18 ms 3068 KB
03_random02.txt AC 119 ms 18196 KB
03_random03.txt AC 99 ms 16404 KB
03_random04.txt AC 98 ms 16404 KB
03_random05.txt AC 26 ms 6140 KB
03_random06.txt AC 23 ms 4092 KB
03_random07.txt AC 32 ms 4476 KB
03_random08.txt AC 9 ms 1788 KB
03_random09.txt AC 41 ms 6524 KB
03_random10.txt AC 68 ms 10364 KB
03_random11.txt AC 116 ms 18068 KB
03_random12.txt AC 118 ms 18196 KB
03_random13.txt AC 93 ms 15508 KB
03_random14.txt AC 75 ms 10620 KB
03_random15.txt AC 32 ms 4476 KB
04_i.txt AC 264 ms 22804 KB
04_p1.txt AC 182 ms 15380 KB
04_p2.txt AC 146 ms 13588 KB
04_random01.txt AC 141 ms 12692 KB
04_random02.txt AC 91 ms 6572 KB
04_random03.txt AC 84 ms 11028 KB
04_random04.txt AC 135 ms 19092 KB
04_random05.txt AC 118 ms 17172 KB
04_random06.txt AC 136 ms 13204 KB
04_random07.txt AC 175 ms 20628 KB
04_random08.txt AC 151 ms 19860 KB
04_random09.txt AC 155 ms 19860 KB
04_random10.txt AC 122 ms 9236 KB
04_random11.txt AC 258 ms 24212 KB
04_random12.txt AC 257 ms 24212 KB
04_random13.txt AC 262 ms 24340 KB
04_rp01.txt AC 184 ms 14740 KB
04_rp02.txt AC 184 ms 14740 KB
04_rp03.txt AC 184 ms 14800 KB
04_rp04.txt AC 186 ms 14740 KB
04_rp05.txt AC 192 ms 14740 KB
04_rp06.txt AC 185 ms 14736 KB
04_rp07.txt AC 183 ms 14740 KB
04_rp08.txt AC 186 ms 14740 KB
04_rp09.txt AC 183 ms 14740 KB
04_rp10.txt AC 184 ms 14740 KB
sample_1.txt AC 7 ms 1788 KB
sample_2.txt AC 7 ms 1788 KB
sample_3.txt AC 7 ms 1788 KB