結果

問題 No.2042 RGB Caps
ユーザー u2dayou2dayo
提出日時 2022-08-20 00:11:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,146 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 97,664 KB
最終ジャッジ日時 2024-04-17 02:40:24
合計ジャッジ時間 3,881 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
56,320 KB
testcase_01 AC 38 ms
55,936 KB
testcase_02 AC 37 ms
56,320 KB
testcase_03 AC 38 ms
56,064 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 76 ms
88,160 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


def main():
    def solve():
        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):
            nxt = C[i:i + 3]
            e = nxt.count("")
            ans[i:i + 3] = C[i:i + 3]
            if e == 3:
                ans[i:i + 3] = "R", "G", "B"
            if e == 2:
                rem = {"R", "G", "B"} - set(nxt)
                for j in range(3):
                    if ans[i + j] == "":
                        ans[i + j] = rem.pop()
            if e == 1:
                rem = {"R", "G", "B"} - set(nxt)
                if len(rem) == 1:
                    for j in range(3):
                        if ans[i + j] == "":
                            ans[i + j] = rem.pop()
                else:
                    flag = False
                    for j in range(3):
                        if ans[i + j] == "":
                            ans[i + j] = rem.pop()
                        else:
                            if flag:
                                ans[i+j] = rem.pop()
                            else:
                                flag = True
            if e == 0:
                ans[i:i + 3] = nxt
        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