結果

問題 No.2042 RGB Caps
ユーザー planesplanes
提出日時 2022-08-19 21:35:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 175,144 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 20:31:05
合計ジャッジ時間 2,997 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

int main() {
    ll N,K;cin>>N>>K;
    vector<pair<ll,char>> vec(K);
    for(ll i=0;i<K;i++) {
      ll A;
      char c;
      cin>>A>>c;
      A--;
      vec[i]=make_pair(A,c);
    }

    sort(all(vec));

    vector<char> ans(N,'C');

    string t="RGB";
    
    for(ll i=0;i<K;i++) {
      ll A=vec[i].first;
      ll k=A/3;
      for(ll j=0;j<3;j++) {
        if(ans[3*k+j]==vec[i].second) break;
        else  if(ans[3*k+j]=='C'){
           ans[3*k+j]=vec[i].second;
           break;
        }
      }
    }



    for(ll i=0;i<N;i+=3) {
      for(ll j=0;j<3;j++) {
        for(ll h=0;h<min(3LL,N-i);h++) {
          if(ans[i+h]==t[j]) break;
          else if(ans[i+h]=='C') {
            ans[i+h]=t[j];
            break;
          }
        }
      }
    }

    for(auto x:ans) cout<<x;
    cout<<endl;



}

0