結果
| 問題 | 
                            No.2042 RGB Caps
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-06-11 00:09:15 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 726 bytes | 
| コンパイル時間 | 262 ms | 
| コンパイル使用メモリ | 12,288 KB | 
| 実行使用メモリ | 34,304 KB | 
| 最終ジャッジ日時 | 2025-01-03 02:07:36 | 
| 合計ジャッジ時間 | 38,303 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 4 TLE * 12 | 
ソースコード
from itertools import product
N, K = map(int, input().split())
testimonials = []
for _ in range(K):
    Ai, ci = input().split()
    Ai = int(Ai)
    testimonials.append((Ai, ci))
possible_colors = ['R', 'G', 'B']
all_possible_hats = product(possible_colors, repeat=N)
def is_valid_configuration(hats):
    for Ai, ci in testimonials:
        color_count = {'R': 0, 'G': 0, 'B': 0}
        for i in range(Ai):
            color_count[hats[i]] += 1
        max_color_count = max(color_count.values())
        if color_count[ci] != max_color_count:
            return False
    
    return True
for hats in all_possible_hats:
    if is_valid_configuration(hats):
        print(''.join(hats))
        break
else:
    print(-1)