Submission #1518947


Source Code Expand

def simulate(s, a)
  (s.size - 2).times do |i|
    a[i + 1] = s[i] ^ a[i - 1] ^ a[i]
  end
  (a[-1] ^ s[-1] == a[0] ^ a[-2] && a[-2] ^ s[-2] == a[-1] ^ a[-3]) ? a : nil
end

n = gets.not_nil!.to_i
s = gets.not_nil!.chars.map { |c| c == 'o' ? 0 : 1 }
a = Array.new(n, 0)
{0, 1}.each do |f|
  a[0] = f
  {0, 1}.each do |l|
    a[-1] = l
    ans = simulate(s, a)
    if ans
      puts ans.map { |i| i == 0 ? "S" : "W" }.join
      exit
    end
  end
end
puts -1

Submission Info

Submission Time
Task D - Menagerie
User tomerun
Language Crystal (0.20.5)
Score 500
Code Size 481 Byte
Status AC
Exec Time 38 ms
Memory 4604 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 16
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 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
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 636 KB
00_example_02.txt AC 1 ms 636 KB
00_example_03.txt AC 1 ms 636 KB
01.txt AC 25 ms 2172 KB
02.txt AC 11 ms 1788 KB
03.txt AC 2 ms 636 KB
04.txt AC 1 ms 636 KB
05.txt AC 34 ms 2940 KB
06.txt AC 21 ms 2940 KB
07.txt AC 7 ms 1020 KB
08.txt AC 5 ms 1020 KB
09.txt AC 2 ms 764 KB
10.txt AC 6 ms 892 KB
11.txt AC 33 ms 4604 KB
12.txt AC 33 ms 3196 KB
13.txt AC 38 ms 3068 KB