結果

問題 No.2042 RGB Caps
ユーザー nyyanyya
提出日時 2022-08-19 22:14:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,711 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 171,652 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 00:54:53
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 49 ms
5,376 KB
testcase_13 AC 50 ms
5,376 KB
testcase_14 AC 50 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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(now != at && g<r) {
                ans[now] = 'G';
                now++,g++;
            }
            while(now != at && b<r) {
                ans[now] = 'B';
                now++,b++;
            }

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

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

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

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

    return 0;
}
0