Submission #13542161


Source Code Expand

Copy
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8,i4[::1])', cache=True)
def solve(dep, T):
    if dep == 0:
        return np.array([0], np.int32)
    A = np.empty(3**dep, np.int32)
    for d in range(3):
        TT = np.empty_like(T)
        p = 0
        x = d
        for t in T:
            if t == 0:
                x = 3 - x if x else 0
                if p > 0 and TT[p - 1] == 0:
                    p -= 1
                else:
                    TT[p] = 0
                    p += 1
            else:
                x = x + 1
                if x == 3:
                    x = 0
                    TT[p] = 1
                    p += 1
        TT = TT[:p]
        A[d::3] = 3 * solve(dep - 1, TT) + x
    return A

N = int(readline())
T = np.frombuffer(read().rstrip(), 'S1')

T = ((T == b'R') * 1).astype(np.int32)

ans = solve(N, T)
print(' '.join(ans.astype(str)))

Submission Info

Submission Time
Task C - Strange Dance
User maspy
Language Python (3.8.2)
Score 1000
Code Size 1043 Byte
Status AC
Exec Time 1106 ms
Memory 193452 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 16
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 477 ms 106536 KB
001.txt AC 457 ms 105544 KB
002.txt AC 458 ms 106024 KB
003.txt AC 456 ms 105568 KB
004.txt AC 457 ms 106204 KB
005.txt AC 1064 ms 193452 KB
006.txt AC 1085 ms 192872 KB
007.txt AC 1096 ms 193200 KB
008.txt AC 1067 ms 192800 KB
009.txt AC 1106 ms 192856 KB
010.txt AC 1061 ms 192860 KB
011.txt AC 1065 ms 192832 KB
012.txt AC 1056 ms 192808 KB
example0.txt AC 478 ms 106060 KB
example1.txt AC 457 ms 105956 KB
example2.txt AC 455 ms 105872 KB