結果

問題 No.2042 RGB Caps
ユーザー milanis48663220milanis48663220
提出日時 2022-08-19 21:31:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,240 bytes
コンパイル時間 1,060 ms
コンパイル使用メモリ 121,112 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 20:30:50
合計ジャッジ時間 2,051 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 7 ms
6,944 KB
testcase_08 AC 12 ms
6,948 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 16 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 19 ms
6,940 KB
testcase_13 AC 17 ms
6,940 KB
testcase_14 AC 17 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int to_int(char c){
    if(c == 'R') return 0;
    if(c == 'G') return 1;
    return 2;
}

const string RGB = "RGB";

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, k; cin >> n >> k;
    vector<int> mx(n, -1);
    for(int i = 0; i < k; i++){
        int a; char c; cin >> a >> c; a--;
        mx[a] = to_int(c);
    }
    
    string ans;
    vector<int> cnt(3);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            bool ok = true;
            auto cc = cnt;
            cc[j]++;
            for(int k = 0; k < 3; k++){
                if(cc[j] > cc[k]+1){
                    ok = false;
                    break;
                }
                if(mx[i] != -1){
                    if(cc[mx[i]] < cc[k]){
                        ok = false;
                        break;
                    }
                }
            }
            if(!ok) continue;
            ans += RGB[j];
            cnt[j]++;
            break;
        }
    }
    cout << ans << endl;
}
0