結果

問題 No.2042 RGB Caps
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-02-22 16:07:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 168,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 23:44:45
合計ジャッジ時間 4,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 26 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 39 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 44 ms
4,380 KB
testcase_13 AC 44 ms
4,380 KB
testcase_14 AC 46 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:37:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   37 |         auto [x, c] = a[i];
      |              ^

ソースコード

diff #

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

using pic = pair<int, char>;


const int N = 1e5 + 10;
int n, k;
pic a[N];

char ans[N];

int cnt[256];

char minc() {
    for(char c : {'R', 'G', 'B'}) {
        bool ok = true;
        for(char v : {'R', 'G', 'B'})
            if(cnt[c] > cnt[v]) {
                ok = false;
                break;
            }
        if(ok) return c;
    }
    return 'r';
}

int main() {
    cin >> n >> k;
    for(int i = 1; i <= k; i ++) {
        cin >> a[i].first >> a[i].second;
    }
    for(int i = 1; i <= n; i ++)
        ans[i] = 'R';
    sort(a + 1, a + k + 1);
    for(int i = 1, cur = 1; i <= k; i ++) {
        auto [x, c] = a[i];
        while(cur < x) ans[cur ++] = minc(), cnt[minc()] ++;
        if(cnt[c] < cnt['R'] || cnt[c] < cnt['G'] || cnt[c] < cnt['B'] || (cnt['R'] == cnt['G'] && cnt['G'] == cnt['B']))
            ans[cur ++] = c, cnt[c] ++;
        else
            ans[cur ++] = minc(), cnt[minc()] ++;
    }

    cout << ans + 1;
}
0