結果

問題 No.2042 RGB Caps
ユーザー umimelumimel
提出日時 2022-08-19 21:51:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 176,324 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 20:33:20
合計ジャッジ時間 2,573 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

int main(){
    ll n, k;
    cin >> n >> k;

    vector<pair<ll, ll>> a(k);
    rep(i, k){
        ll A;
        char c;
        cin >> A >> c;
        a[i].fi = A;
        if(c=='R'){
            a[i].se = 0;
        }else if(c=='G'){
            a[i].se = 1;
        }else{
            a[i].se = 2;
        }
    }
    sort(all(a));

    ll m = n + (3 - n%3)%3;
    vector<ll> color(m+1, -1);
    ll now = 0;
    for(ll i=1; i<=m; i+=3){
        vector<bool> used(3, false);
        rep(j, 3){
            if(i+j == a[now].fi){
                if(used[a[now].se]){
                    rep(l, 3){
                        if(!used[l]){
                            used[l] = true;
                            color[i+j] = l;
                            break;
                        }
                    }
                }else{
                    color[i+j] = a[now].se;
                    used[color[i+j]] = true;
                }
                now++;
            }else{
                rep(l, 3){
                    if(!used[l]){
                        used[l] = true;
                        color[i+j] = l;
                        break;
                    }
                }
            }
        }
    }

    char x[3] = {'R', 'G', 'B'};
    for(ll i=1; i<=n; i++) cout << x[color[i]];
    cout << endl;
}
0