結果

問題 No.2042 RGB Caps
ユーザー nyyanyya
提出日時 2022-08-19 22:32:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,426 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 173,496 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 01:10:22
合計ジャッジ時間 3,540 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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(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 && 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(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 && b<g) {
                ans[now] = 'B';
                now++,r++;
            }
            while(now != at && r<g) {
                ans[now] = 'R';
                now++,r++;
            }

        } 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 && 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