結果
| 問題 | 
                            No.2042 RGB Caps
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hiro71687k
                         | 
                    
| 提出日時 | 2023-04-15 16:56:30 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 46 ms / 2,000 ms | 
| コード長 | 1,906 bytes | 
| コンパイル時間 | 3,764 ms | 
| コンパイル使用メモリ | 254,864 KB | 
| 最終ジャッジ日時 | 2025-02-12 08:56:24 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 16 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:76:13: warning: ‘r’ may be used uninitialized [-Wmaybe-uninitialized]
   76 |             if (r>0)
      |             ^~
main.cpp:26:8: note: ‘r’ was declared here
   26 |     ll r,b,g;
      |        ^
main.cpp:54:17: warning: ‘b’ may be used uninitialized [-Wmaybe-uninitialized]
   54 |                 if (b==1)
      |                 ^~
main.cpp:26:10: note: ‘b’ was declared here
   26 |     ll r,b,g;
      |          ^
main.cpp:80:19: warning: ‘g’ may be used uninitialized [-Wmaybe-uninitialized]
   80 |             }else if (g>0)
      |                   ^~
main.cpp:26:12: note: ‘g’ was declared here
   26 |     ll r,b,g;
      |            ^
            
            ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=144499999999994;
ll mod=1000000007;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<pair<ll,char>>p(k);
    for (ll i = 0; i < k; i++)
    {
        cin >> p[i].first >> p[i].second;
        p[i].first--;
    }
    sort(p.begin(),p.end());
    string s;
    for (ll i = 0; i < n; i++)
    {
        s.push_back('N');
    }
    ll now=0;
    ll r,b,g;
    for (ll i = 0; i < n; i++)
    {
        if (i%3==0)
        {
            r=1,b=1,g=1;
        }
        if (p[now].first==i)
        {
            if (p[now].second=='R')
            {
                if (r==1)
                {
                    s[i]='R';
                    r=0;
                    now+=1;
                    continue;
                }
            }else if (p[now].second=='G')
            {
                if (g==1)
                {
                    s[i]='G';
                    g=0;
                    now+=1;
                    continue;
                }
            }else{
                if (b==1)
                {
                    s[i]='B';
                    b=0;
                    now+=1;
                    continue;
                }
            }
            if (r>0)
            {
                s[i]='R';
                r=0;
            }else if (g>0)
            {
                s[i]='G';
                g=0;
            }else{
                s[i]='B';
                b=0;
            }
            now+=1;
        }else{
            if (r>0)
            {
                s[i]='R';
                r=0;
            }else if (g>0)
            {
                s[i]='G';
                g=0;
            }else{
                s[i]='B';
                b=0;
            }
        }
    }
    cout << s << endl;
}
            
            
            
        
            
hiro71687k