Created
May 15, 2021 11:00
-
-
Save Wizmann/d6682688fbe52c03d31112ab87e4fc25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
from random import randint | |
INF = 10 ** 10 | |
P1 = 860939810732536850 | |
P2 = 937467793908762347 | |
T = 50 | |
N = 20 | |
B = 15 | |
def readint(): | |
return int(raw_input()) | |
def solve(): | |
digits = [30 for i in xrange(10)] | |
scores = [0 for i in xrange(B + 1)] | |
blocks = [0 for i in xrange(B + 1)] | |
towers = [0 for i in xrange(N)] | |
blocks[0] = INF | |
for i in xrange(N * B): | |
cur = readint() | |
exp = sum(digits[cur + 1: 10]) | |
level = B | |
while exp > 0 and level > 0: | |
exp -= N - blocks[level] | |
if exp >= 0: | |
level -= 1 | |
digits[cur] = digits[cur] - 1 | |
flag = False | |
chk = 0 | |
while level >= 1: | |
if blocks[level] < N and blocks[level] + 1 <= blocks[level - 1]: | |
scores[level] += cur | |
blocks[level] += 1 | |
chk = level | |
flag = True | |
break | |
level -= 1 | |
if not flag: | |
level = 1 | |
while level <= B: | |
if blocks[level] < N and blocks[level] + 1 <= blocks[level - 1]: | |
scores[level] += cur | |
blocks[level] += 1 | |
flag = True | |
chk = level | |
break | |
level += 1 | |
assert flag | |
assert chk == level | |
for j in xrange(N): | |
if towers[j] == level - 1: | |
towers[j] = level | |
print j + 1 | |
sys.stdout.flush() | |
break | |
else: | |
assert False | |
''' | |
for i in xrange(1, B + 1): | |
assert blocks[i] <= blocks[i - 1] | |
''' | |
res = 0 | |
# print blocks | |
for i in xrange(1, B + 1): | |
assert blocks[i] == N | |
res += (10 ** (i - 1)) * scores[i] | |
# sys.stderr.write('%d\n' % res) | |
return res | |
# random.seed(1000) | |
T, N, B, P = map(int, raw_input().split()) | |
res = 0 | |
for case_ in xrange(T): | |
res += solve() | |
# print res | |
sys.stdout.flush() | |
# sys.stderr.write('%d\n' % res) | |
judge = raw_input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment