CSES - E4590 2016 6 - Results
Submission details
Task:Rotations
Sender:smolse
Submission time:2016-10-24 14:37:31 +0300
Language:Python3
Status:READY
Result:
Test results
testverdicttime
#10.09 sdetails
#20.07 sdetails
#30.07 sdetails
#40.05 sdetails
#50.07 sdetails
#60.08 sdetails
#70.07 sdetails
#8UNKNOWN--details
#9UNKNOWN--details
#10UNKNOWN--details
#11UNKNOWN--details
#12UNKNOWN--details

Code

import fileinput
from math import pow
import time

VALS = {
    'A': 0,
    'C': 1,
    'T': 2,
    'G': 3
}
P = 5

hashes = {
    1: set(),
    2: set(),
    3: set(),
    4: set(),
    5: set(),
    6: set(),
    7: set(),
    8: set(),
    9: set(),
    10: set()
}

lhs = {
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0,
    10: 0
}

def hash(q):
    _hash = 0
    lq = len(q)
    for i in range(lq):
        _hash += VALS[q[i]] * pow(P, lq-i-1)
    return _hash

a = time.time()

lh = 0

seq = ''

seen_no = {
    1: set(),
    2: set(),
    3: set(),
    4: set(),
    5: set(),
    6: set(),
    7: set(),
    8: set(),
    9: set(),
    10: set(),
}


with fileinput.input(['-']) as input:
    seq = input.readline().rstrip()
    q = int(input.readline().rstrip())
    ls = len(seq)
    subseqs = []
    for _ in range(q):
        subseq = input.readline().rstrip()
        subseqs.append(subseq)
    for subseq in sorted(subseqs, key=len):
        lss = len(subseq)
        if lss > ls:
            print('NO')
            continue
        x = False
        for i in range(1, len(subseq)):
            if subseq[0:i] in seen_no[i]:
                x = True
                break
        if x:
            print('NO')
            continue
        subseq_hash = hash(subseq)
        if subseq_hash in hashes[lss]:
            print('YES')
        else:
            f = False
            prev_hash = None
            for i in range(lhs[lss], ls-lss+1):
                if prev_hash is None:
                    h = hash(seq[lhs[lss]:lhs[lss]+lss])
                else:
                    h = prev_hash * P - VALS[seq[lhs[lss]-1]] * pow(P, lss) + VALS[seq[lhs[lss] + lss - 1]]
                hashes[lss].add(h)
                lhs[lss] += 1
                prev_hash = h
                if h == subseq_hash:
                    f = True
                    break
            print('YES' if f else 'NO')
            if not f:
                seen_no[lss].add(subseq)
    #print(hashes)

#print(time.time() - a)

Test details

Test 1

Verdict:

input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 68, in <module>
    q = int(input.readline().rstrip())
ValueError: invalid literal for int() with base 10: ''

Test 2

Verdict:

input
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

correct output
abbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 68, in <module>
    q = int(input.readline().rstrip())
ValueError: invalid literal for int() with base 10: ''

Test 3

Verdict:

input
jibanqfglkmsywdlqjquxxnqeyhbyu...

correct output
aaadptqmkuqxnvmojzhghqtfztbwsj...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 68, in <module>
    q = int(input.readline().rstrip())
ValueError: invalid literal for int() with base 10: ''

Test 4

Verdict:

input
muykjgvsstkgydmumitbgvsbtgyvmv...

correct output
aaaeaeipiqglrtbzelgrqmrxqbnjke...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 68, in <module>
    q = int(input.readline().rstrip())
ValueError: invalid literal for int() with base 10: ''

Test 5

Verdict:

input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 68, in <module>
    q = int(input.readline().rstrip())
ValueError: invalid literal for int() with base 10: ''

Test 6

Verdict:

input
aaaaaaaaabaaaaaaaaabaaaaaaaaab...

correct output
aaaaaaaaabaaaaaaaaabaaaaaaaaab...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 68, in <module>
    q = int(input.readline().rstrip())
ValueError: invalid literal for int() with base 10: ''

Test 7

Verdict:

input
jtcbpjizbiauauipwsdteaisynwesj...

correct output
aisynwesjvtvgghnbqyqprwpfqayzl...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 68, in <module>
    q = int(input.readline().rstrip())
ValueError: invalid literal for int() with base 10: ''

Test 8

Verdict: UNKNOWN

input
a

correct output
a

user output
(not available)

Test 9

Verdict: UNKNOWN

input
ab

correct output
ab

user output
(not available)

Test 10

Verdict: UNKNOWN

input
ba

correct output
ab

user output
(not available)

Test 11

Verdict: UNKNOWN

input
home

correct output
ehom

user output
(not available)

Test 12

Verdict: UNKNOWN

input
baaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

user output
(not available)