結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 13 ms
6,940 KB
testcase_08 AC 27 ms
6,940 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 41 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 48 ms
6,940 KB
testcase_13 AC 45 ms
6,940 KB
testcase_14 AC 45 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   23 |         auto [at,ct] = a[i];
      |              ^

ソースコード

diff #

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

int main(){

    int n,k;
    cin >> n >> k;

    vector<pair<int,char>> a(k); 

    for(int i=0;i<k;i++){
        int at;
        char ct;
        cin >> at >> ct;
        a[i] = make_pair(at,ct);
    }
    sort(a.begin(),a.end());

    vector<char> ans(n);
    bool check = false;
    int now=0,r=0,g=0,b=0;
    for(int i=0;i<k;i++){
        auto [at,ct] = a[i];

        if(ct == 'R'){
            while(r < (at+2)/3) {
                ans[now] = 'R';
                now++,r++;
            }
            while(g<b && g<r && now != at) {
                ans[now] = 'G';
                now++,g++;
            }
            while(b<g && b<r && now != at) {
                ans[now] = 'B';
                now++,b++;
            }
 
            while(now != at) {
                ans[now] = 'G';
                now++,g++;
                if(now != at){
                    ans[now] = 'B';
                    now++,b++;
                }
            }

        } else if(ct == 'G') {
            while(g < (at+2)/3) {
                ans[now] = 'G';
                now++,g++;
            }
            while(r<b && r<g && now != at) {
                ans[now] = 'R';
                now++,r++;
            }
            while(b<r && b<g && now != at) {
                ans[now] = 'B';
                now++,b++;
            }


            while(now != at) {
                ans[now] = 'R';
                now++,r++;
                if(now != at){
                    ans[now] = 'B';
                    now++,b++;
                }
            }

        } else {
            while(b < (at+2)/3) {
                ans[now] = 'B';
                now++,b++;
            }
            while(r<g && r<b && now != at) {
                ans[now] = 'R';
                now++,r++;
            }
            while(g<r && g<b && now != at) {
                ans[now] = 'G';
                now++,g++;
            }

            while(now != at) {
                ans[now] = 'R';
                now++,r++;
                if(now != at){
                    ans[now] = 'G';
                    now++,g++;
                }
            }

        }

        if(now != at) {
            check = true;
            break;
        }
    }

    while(now != n) ans[now++] = 'R';

    if(check) cout << -1 << endl;
    else {
        for(int i=0;i<n;i++) cout << ans[i] ;
        cout << endl;
    }
    

    return 0;
}
0