結果

問題 No.2042 RGB Caps
ユーザー uytvccuytvcc
提出日時 2022-08-19 21:59:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,149 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 180,284 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-27 20:33:23
合計ジャッジ時間 2,833 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 23 ms
8,192 KB
testcase_07 AC 18 ms
6,944 KB
testcase_08 AC 37 ms
7,040 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 53 ms
8,192 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 AC 60 ms
8,320 KB
testcase_13 AC 59 ms
8,448 KB
testcase_14 AC 58 ms
8,448 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 16 ms
6,940 KB
testcase_17 AC 5 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:71:29: warning: 'minc' may be used uninitialized [-Wmaybe-uninitialized]
   71 |                 ans+=st[minc];
      |                             ^
main.cpp:61:13: note: 'minc' was declared here
   61 |         int minc;
      |             ^~~~
main.cpp:48:16: warning: 'col' may be used uninitialized [-Wmaybe-uninitialized]
   48 |         mp[--a]=col;
main.cpp:44:13: note: 'col' was declared here
   44 |         int col;
      |             ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define MOD2 998244353
#define INF 1000000007
#define LINF 1000000000000000007LL
#define PI 3.14159265359
#define P pair<ll,ll>
template <typename T>
inline bool chmax(T &a, const T &b){
    if(a<b) {a=b; return true;}
    else return false;
}
template <typename T>
inline bool chmin(T &a, const T &b){
    if(a>b) {a=b; return true;}
    else return false;
}
struct Edge{
    int to; ll cost; int rev;
    Edge(int to, ll cost, int rev) : to(to), cost(cost), rev(rev) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g,int from,int to,ll cost,bool revFlag,ll revCost){
    g[from].push_back(Edge(to,cost,g[to].size()));
    if(revFlag) g[to].push_back(Edge(from,revCost,g[from].size()-1));
}

string st = "RGB";

void solve(){
    int n,k;
    cin>>n>>k;
    map<int,int> mp;
    rep(i,k){
        int a; char c;
        cin>>a>>c;
        int col;
        if(c=='R') col=1;
        if(c=='G') col=2;
        if(c=='B') col=3;
        mp[--a]=col;
    }

    string ans="";
    vector<int> col(3,0);
    int m=1;
    bool exist=1;
    rep(i,n){
        if(mp[i]==0){
            m++;
            continue;
        }
        int c=mp[i]-1;
        int minc;
        rep(j,m){
            int cnt=INF;
            rep(x,3){
                if(chmin(cnt,col[x])) minc=x;
            }
            if((col[c]<col[0] || col[c]<col[1] || col[c]<col[2]) || (col[0]==col[1] && col[1]==col[2])){
                ans+=st[c];
                col[c]++;
            }else{
                ans+=st[minc];
                col[minc]++;
            }
        }
        if(col[c]<col[0] || col[c]<col[1] || col[c]<col[2]) exist=0;
        m=1;
    }
    rep(j,m-1) ans += 'R';
    if(!exist) cout<<-1<<endl;
    else cout<<ans<<endl;
}   

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<setprecision(10)<<fixed;
    solve();
    return 0;
}
0