結果

問題 No.2042 RGB Caps
コンテスト
ユーザー vjudge1
提出日時 2025-11-05 16:36:16
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 2,422 bytes
コンパイル時間 3,205 ms
コンパイル使用メモリ 292,812 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-05 16:36:29
合計ジャッジ時間 4,594 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// Template
// ==============================================
    // pbds
    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/pb_ds/tree_policy.hpp>
    // using namespace __gnu_pbds;
    // template<typename T, typename comp = less<T>>
    // using ordered_set =  tree<T, null_type, comp, rb_tree_tag, tree_order_statistics_node_update>;

    // Debugging
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...)
    #define see(x)
    #endif

    typedef long long ll;
    typedef vector<int> VI;
    typedef vector<long long> VLL;
    typedef vector<bool> VB;
    typedef vector<vector<int>> VVI;
    typedef pair<int, int> PI;
    typedef pair<ll, ll> PLL;
    typedef vector<pair<int, int>> VPI;

    #define pb push_back
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(a) a.begin(), a.end()
    #define revall(a) a.rbegin(), a.rend()

    #define loop(i, s, e) for (int i = s; i < e; ++i)
    #define inp(v) for (auto& x : v) cin >> x
    #define outp(v) for (int i = 0, n = v.size(); i < n; ++i) cout << v[i] << " \n"[i == n - 1]

    #define nl "\n"
    #define yep cout << "YES\n"
    #define nope cout << "NO\n"

    #define INF (int) 1e9
    #define INFL (ll) 1e18
    // #define MOD 998244353
    #define MOD 1000000007
    #define MAXN 100002
// =============================================

void solve(int tc)
{
    int n, k; cin >> n >> k;

    vector<pair<int, char>> c(k);
    loop(i, 0, k) cin >> c[i].ff >> c[i].ss;
    sort(revall(c));

    vector<char> ans(n, '#');
    for (int i = 0; i < n; i += 3)
    {
        set s = {'R', 'G', 'B'};
        while (!c.empty() && c.back().ff <= i + 3)
        {
            if (s.contains(c.back().ss)) ans[c.back().ff - 1] = c.back().ss;
            s.erase(c.back().ss);
            c.pop_back();
        }

        loop(j, i, min(i + 3, n))
        {
            if (ans[j] == '#')
            {
                ans[j] = *s.begin();
                s.erase(s.begin());
            }
        }
    }

    loop(i, 0, n) cout << ans[i];
    cout << nl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t = 1;
    // cin >> t;
    int x = t;
    while(t--) solve(x - t);
    
    #ifdef LOCAL
    cerr << "Execution time: " << 1000.f * clock() / CLOCKS_PER_SEC << " ms." << nl;
    #endif
    
    return 0;
}
0