Task: | Ruudukko |
Sender: | okkokko |
Submission time: | 2022-11-09 23:56:51 +0200 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | 61 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 28 |
#2 | ACCEPTED | 33 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.07 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.07 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.07 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.09 s | 2, 3 | details |
#5 | ACCEPTED | 0.09 s | 2, 3 | details |
#6 | ACCEPTED | 0.11 s | 2, 3 | details |
#7 | TIME LIMIT EXCEEDED | -- | 3 | details |
#8 | TIME LIMIT EXCEEDED | -- | 3 | details |
#9 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
# completes tests 1 and 2, but not 3import randomimport timeimport sysfrom typing import Generator, TypeVarimport itertoolsdef I():return map(int, input().split())# DIVISOR = 10**9 + 7_V = TypeVar("_V")test_N = 1000test_seed = 1001# seed is 1001test_expected_results = {100: 773224951,200: 452330452,300: 37161558,400: 250332178,1000: 298053617}def test():n = test_Ndef text_gen():yield str(n)random.seed(test_seed)for i in range(n):yield " ".join((str(random.randint(1, n * n)) for _ in range(n)))return iter(list(text_gen())).__next__# input = test()timer_init = time.perf_counter()class Node:# ended up unused"Binary Search Tree node"def __init__(self, parent: "Node|None", left: "Node|None", right: "Node|None", key: "int|float"):self.key = keyself.parent = parentself.left = leftself.right = rightself.values = []self.marker = 0passdef Get(self) -> "list":return self.values...def Add(self, value):self.values.append(value)def next(self):if self.marker == 0:self.marker += 1if self.left:return self.leftif self.marker == 1:self.marker += 1if self.right:return self.rightself.marker = 0return self.parentclass BST:# ended up unuseddef __init__(self, middle: float):self.root = Node(None, None, None, middle)def Insert(self, key: "int | float", value: "_V"):node, pos = self.search(key)if pos == 1:node.left = Node(node, None, None, key)node.left.Add(value)elif pos == 2:node.right = Node(node, None, None, key)node.right.Add(value)else:node.Add(value)# def Get(self, key: "int | float") -> "Node":# ...def Iter(self) -> "Generator[Node,None,None]":node = self.rootwhile 1:new = node.next()if new is None:breakif node.marker == 0:# new is parentif new.marker == 1:# node is leftyield newelif new.left is None:yield new# elif node.marker == 1:# # new is right childnode = newdef Iter_Values(self):# for node in self.Iter():# for x, y in node.Get():# yield node.key, x, yreturn ((node.key, v) for node in self.Iter() for v in node.Get())def search(self, key: "int|float") -> "tuple[Node, int]":"""returns a node and a number.0 means the node has the wanted value,1 means the value doesn't exist but would be the node's left branch if inserted,2 means the same as 1 but for the right branch."""# no recursioncurrent = self.rootwhile 1:if key < current.key:if current.left:current = current.leftelse:return current, 1elif key > current.key:if current.right:current = current.rightelse:return current, 2else:return current, 0def timer(desc: "str", prev: "float"):t = time.perf_counter()print(desc, t - prev, file=sys.stderr)return tdef main():DIVISOR = 10**9 + 7timer_0 = time.perf_counter()n, = I()grid = [list(I()) for _ in range(n)]sett = list((grid[y][x], x, y) for y in range(n) for x in range(n))# sett = set((a, x, y) for (y, x), a in zip(itertools.product(range(n), repeat=2), itertools.chain(*(I() for _ in range(n)))))timer_1 = timer("timer 1:", timer_0)line_row = [0] * nline_row_last = [1] * nline_col = [0] * nline_col_last = [1] * nline_row_added = [0] * nline_col_added = [0] * ntimer_2 = timer("timer 2:", timer_1)sor = sorted(sett, key=lambda x: x[0])timer_3 = timer("sorting:", timer_2)total = 0for number, x, y in sor:if number != line_row_last[y]:line_row_last[y] = numberline_row[y] += line_row_added[y]line_row_added[y] = 0if number != line_col_last[x]:line_col_last[x] = numberline_col[x] += line_col_added[x]line_col_added[x] = 0value = (line_col[x] + line_row[y] + 1) % DIVISORline_row_added[y] += valueline_col_added[x] += valuetotal += value# total = sum(calculate_routes(y, x, k)for k, x, y in sor)# total = sum(calculate_routes_full(*s)for s in sor)timer_4 = timer("timer 4:", timer_3)return total % DIVISORdef old_iteration(n, grid, exists_row, exists_all, calculate_routes):for a in range(1, n * n + 1):if a not in exists_all:continuefor y in range(n):if a not in exists_row[y]:continuex = -1try:while True:x = grid[y].index(a, x + 1)calculate_routes(y, x, a)except ValueError:passtimer_start = time.perf_counter()w = main()print(w)# 100: 773224951# 200: 452330452timer_end = time.perf_counter()print("time:", timer_end - timer_start,("\ncorrect" if w == test_expected_results[test_N] else "\ndifferent") if test_N in test_expected_results.keys() else "no data",# "\ninit:", timer_start - timer_init,"\nseed:", test_seed,file=sys.stderr)
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 1 1 1 1 1 1 1 1 1 |
correct output |
---|
9 |
user output |
---|
9 |
Error:
timer 1: 0.00020664592739194632 timer 2: 2.742407377809286e-05 sorting: 2.7357949875295162...
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 1 2 3 6 5 4 7 8 9 |
correct output |
---|
135 |
user output |
---|
135 |
Error:
timer 1: 0.00019310100469738245 timer 2: 2.7289963327348232e-05 sorting: 2.771697472780943...
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 7 8 1 4 5 4 3 9 6 |
correct output |
---|
57 |
user output |
---|
57 |
Error:
timer 1: 0.00018205400556325912 timer 2: 2.65931012108922e-05 sorting: 2.6968889869749546e...
Test 4
Group: 2, 3
Verdict: ACCEPTED
input |
---|
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
10000 |
user output |
---|
10000 |
Error:
timer 1: 0.0109414680628106 timer 2: 6.188603583723307e-05 sorting: 0.0036987699568271637...
Test 5
Group: 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
187458477 |
user output |
---|
187458477 |
Error:
timer 1: 0.010855545056983829 timer 2: 6.181898061186075e-05 sorting: 0.00383433501701802...
Test 6
Group: 2, 3
Verdict: ACCEPTED
input |
---|
100 2995 8734 1018 2513 7971 5063 ... |
correct output |
---|
964692694 |
user output |
---|
964692694 |
Error:
timer 1: 0.012620743014849722 timer 2: 6.153108552098274e-05 sorting: 0.01132322195917368...
Test 7
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
1000000 |
user output |
---|
(empty) |
Test 8
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
229147081 |
user output |
---|
(empty) |
Test 9
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 520283 805991 492643 75254 527... |
correct output |
---|
951147313 |
user output |
---|
(empty) |