結果

問題 No.2042 RGB Caps
ユーザー やうやう
提出日時 2022-08-19 21:39:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,257 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 169,864 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-04-17 00:20:08
合計ジャッジ時間 4,629 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 16 ms
9,216 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
using ps=pair<int,string>;
using V=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)

int main(){
    int n,q;
    cin >> n >> q;
    V a(n,-1);
    rep(i,q){
        int x; char c;
        cin >> x >> c;
        x--;
        if(c=='R') a[x]=0;
        if(c=='G') a[x]=1;
        if(c=='B') a[x]=2;
    }
    vector<V> s(n+5,V(3));
    rep(i,n){
        bool f=(a[i]==-1);
        if(!f){
            if(max({s[i][0],s[i][1],s[i][2]})<=s[i][a[i]]) f=true;
        }
        if(f){
            bool bl=true;
            rep(j,3) if(s[i][j]<max({s[i][0],s[i][1],s[i][2]})&&bl){
                s[i][j]++; bl=false;
            }
            if(bl) s[i][0]++;
        }
        else{
            s[i][a[i]]++;
            if(s[i][a[i]]<max({s[i][0],s[i][1],s[i][2]})){
                cout << -1 << endl;
                return 0;
            }
        }
        rep(j,3) s[i+1][j]=s[i][j];
    }
    
    for(int i=n-1;0<=i;i--) rep(j,3) s[i+1][j]-=s[i][j];

    rep(i,n) rep(j,3) if(s[i][j]){
        if(j==0) cout << "R";
        if(j==1) cout << "G";
        if(j==2) cout << "B";
    }
    cout << endl;

}
0