結果

問題 No.2042 RGB Caps
ユーザー やうやう
提出日時 2022-08-19 21:50:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,257 bytes
コンパイル時間 1,394 ms
コンパイル使用メモリ 173,664 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-04-27 20:32:57
合計ジャッジ時間 2,572 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 13 ms
9,088 KB
testcase_07 AC 14 ms
6,940 KB
testcase_08 AC 28 ms
7,552 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 40 ms
8,960 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 42 ms
9,088 KB
testcase_13 AC 45 ms
9,216 KB
testcase_14 AC 45 ms
9,104 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 13 ms
6,944 KB
testcase_17 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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){
        int m=1e9,M=0;
        rep(j,3){
            M=max(M,s[i][j]);
            m=min(m,s[i][j]);
        }
        bool f=(a[i]==-1);
        if(!f) if(m<s[i][a[i]]) f=true;
        if(f){
            bool bl=true;
            rep(j,3) if(s[i][j]<M&&bl){
                s[i][j]++; bl=false;
            }
            if(bl) s[i][0]++;
        }
        else{
            s[i][a[i]]++;
            if(s[i][a[i]]<M){
                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