結果

問題 No.2042 RGB Caps
ユーザー u2dayou2dayo
提出日時 2022-08-20 00:17:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 3,449 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 99,712 KB
最終ジャッジ日時 2024-04-27 20:36:42
合計ジャッジ時間 2,833 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,936 KB
testcase_01 AC 41 ms
55,424 KB
testcase_02 AC 42 ms
55,680 KB
testcase_03 AC 42 ms
55,936 KB
testcase_04 AC 42 ms
55,808 KB
testcase_05 AC 44 ms
55,424 KB
testcase_06 AC 120 ms
97,152 KB
testcase_07 AC 116 ms
84,224 KB
testcase_08 AC 149 ms
93,312 KB
testcase_09 AC 102 ms
79,744 KB
testcase_10 AC 167 ms
99,712 KB
testcase_11 AC 107 ms
81,152 KB
testcase_12 AC 171 ms
99,712 KB
testcase_13 AC 169 ms
99,584 KB
testcase_14 AC 177 ms
99,700 KB
testcase_15 AC 45 ms
56,448 KB
testcase_16 AC 122 ms
83,424 KB
testcase_17 AC 97 ms
78,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""2022.08.19 23:52:58 JST"""
import sys
from functools import partial, reduce, lru_cache
from itertools import groupby, islice, tee, permutations


def main():
    def solve():
        def judge(s):
            used = set()
            for j in range(3):
                used.add(s[j])
                if C[i + j] != "" and C[i + j] not in used:
                    return False
            return True

        N, K = map(int, readline().split())
        C = [""] * (divceil(N, 3) * 3)
        for _ in range(K):
            _A, c = readline().split()
            C[int(_A) - 1] = c
        ans = [""] * (divceil(N, 3) * 3)

        for i in range(0, (divceil(N, 3) * 3), 3):
            for s in permutations("RGB"):
                if judge(s):
                    ans[i:i+3] = s
                    break
        return ans[:N]

    print_nospace(*solve())

    # @formatter:off
"+-+-+-+ Constants +-+-+-+"
MOD = 10 ** 9 + 7
# MOD = 998_244_353
INF = (1 << 62) - 1
"+-+-+-+ Settings +-+-+-+"
# sys.setrecursionlimit(10 ** 6)
# if "pypyjit" in sys.builtin_module_names:import pypyjit;pypyjit.set_param("max_unroll_recursion=-1");
use_buffer_read = False
"+-+-+-+ Libraries +-+-+-+"

"+-+-+-+ Memorize +-+-+-+"
_imm={}
"+-+-+-+ Print +-+-+-+"
printd=partial(print,file=sys.stderr,flush=True)
printd_nospace=partial(print,sep='',file=sys.stderr,flush=True)
printd_line=partial(print,sep='\n',file=sys.stderr,flush=True)
printd_mat=lambda mat:[print(*v,file=sys.stderr,flush=True) for v in mat]
print_nospace=partial(print,sep='')
print_line=partial(print,sep='\n')
print_mat=lambda mat:[print(*v) for v in mat]
"+-+-+-+ Math +-+-+-+"
aseq_sum1=lambda a1,d,n:n*(2*a1+(n-1)*d)//2
aseq_sum2=lambda a1,an,n:n*(a1+an)//2
aseq_msum1=lambda a1,d,n:(n*(2*a1+(n-1)*d)*invmod(2))%MOD
aseq_msum2=lambda a1,an,n:(n*(a1+an)*invmod(2)) % MOD
gseq_sum=lambda a,r,n:a*(pow(r,n)-1)//(r-1) if r!=1 else a*n
gseq_msum=lambda a,r,n:a*(pow(r,n,MOD)-1)*invmod(r-1)%MOD if r!=1 else a*n%MOD
divceil=lambda x,y:(x+y-1)//y
invmod=lambda x:_imm.setdefault(x,pow(x,MOD-2,MOD))
powmod=partial(pow,mod=MOD)
"+-+-+-+ Iter +-+-+-+"
crange=lambda *args:range(args[0]+1) if len(args)==1 else range(args[0],args[1]+1,1 if len(args)==2 else args[2])
rrange=lambda *args:reversed(range(*args))
"+-+-+-+ List +-+-+-+"
cst2l=lambda first,second,initial=0:[[initial]*second for _ in range(first)]
copy2l=lambda L:[r[:] for r in L]
"+-+-+-+ String +-+-+-+"
concat=lambda L,sep='':sep.join(L)
ston=lambda S,a=0:[(ord(c)|32)-(97-a) for c in S]
"+-+-+-+ Algorithms +-+-+-+"
ccomp=lambda A:{x:i for i,x in enumerate(sorted(set(A)))}
invert=lambda A,start=0:dict(zip(A,range(start,len(A)+start)))
lpartion = lambda L,b:[L[i:i+b] for i in range(0,len(L),b)]
nwise=lambda n,A:zip(*(islice(it,s,None) for it,s in zip(tee(A,n),range(n))))
runlength=lambda A:[[k,len(list(g))] for k,g in groupby(A)]
__c1=0x5555555555555555;__c2=0x3333333333333333;__c3=0xf0f0f0f0f0f0f0f;__c4=0xff00ff00ff00ff;__c5=0xffff0000ffff;__c6=0xffffffff;
def popcount(n):c=(n&__c1)+((n>>1)&__c1);c=(c&__c2)+((c>>2)&__c2);c=(c&__c3)+((c>>4)&__c3);c=(c&__c4)+((c>>8)&__c4);c=(c&__c5)+((c>>16)&__c5);c=(c&__c6)+((c>>32)&__c6);return c
"+-+-+-+ Read +-+-+-+"
__file=open(0)
read=__file.buffer.read if use_buffer_read else __file.read
readline=__file.buffer.readline if use_buffer_read else __file.readline
readlines=__file.buffer.readlines if use_buffer_read else __file.readlines
"+-+-+-+ Run +-+-+-+"
main()
# @formatter:on
0