結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 15 ms
5,376 KB
testcase_08 AC 30 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 43 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 50 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 AC 5 ms
5,376 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;
        }
    }

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

    return 0;
}
0