結果

問題 No.2042 RGB Caps
ユーザー ripityripity
提出日時 2022-11-01 22:13:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 205,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 11:10:34
合計ジャッジ時間 4,813 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 23 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 37 ms
4,380 KB
testcase_13 AC 36 ms
4,376 KB
testcase_14 AC 36 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K, M = 100002;
    cin >> N >> K;
    vector<int> A(K);
    vector<char> c(K), ans(M, 'A');
    vector<string> str = {"BGR", "BRG", "GBR", "GRB", "RBG", "RGB"};
    for( int i = 0; i < K; i++ ) {
        cin >> A[i] >> c[i];
        ans[--A[i]] = c[i];
    }
    for( int i = 0; i < M; i+=3 ) {
        string str2 = "AAA";
        for( int j = 0; j < 3; j++ ) {
            for( int k = 0; k < 3; k++ ) {
                if( str2[k] == ans[i+j] ) break;
                if( str2[k] != 'A' ) continue;
                if( str2[k] == 'A' ) {
                    str2[k] = ans[i+j];
                    break;
                }
            }
        }
        // cout << str2 << endl;
        // cout << *lower_bound(str.begin(), str.end(), str2) << endl;
        str2 = *lower_bound(str.begin(), str.end(), str2);
        for( int j = 0; j < 3; j++ ) {
            ans[i+j] = str2[j];
        }
    }
    for( int i = 0; i < N; i++ ) {
        cout << ans[i];
    }
    cout << endl;
}
0