結果

問題 No.2042 RGB Caps
コンテスト
ユーザー vjudge1
提出日時 2025-11-05 17:23:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,039 bytes
コンパイル時間 3,498 ms
コンパイル使用メモリ 290,936 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2025-11-05 17:23:29
合計ジャッジ時間 6,952 ms
ジャッジサーバーID
(参考情報)
judge1 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 3 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /usr/include/c++/13/string:54,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from main.cpp:1:
In member function ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’,
    inlined from ‘int main()’ at main.cpp:61:23:
/usr/include/c++/13/bits/basic_string.h:1388:24: warning: ‘last’ may be used uninitialized [-Wmaybe-uninitialized]
 1388 |         this->push_back(__c);
      |         ~~~~~~~~~~~~~~~^~~~~
main.cpp: In function ‘int main()’:
main.cpp:23:9: note: ‘last’ was declared here
   23 |    char last;
      |         ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define nl endl

signed main(){
   int n,k; cin >> n >> k;
   
   map<int,char>m;
   
   string ans ="";
   set<char>st;
   
   for(int i = 0; i < k; i++){
       int x; cin >> x;
       char c; cin >> c;
       m[x] = c;
       st.insert(c);
   } 
   
   vector<char>v(st.begin(),st.end());
   
   char last;
   vector<char>check;
   for(auto [x,y]: m){
       last = y;
       check.push_back(y);
   }
   
   char ss = check[check.size() - 1];
   int ii = check.size() - 1;
   
   while(check[ii] == ss){
       ii--;
   }
   char slast = check[ii];
   
   int c1 = 0, c2 = 0, c3 = 0;
   if(st.size() == 1){
       for(int i = 0; i < n; i++) ans += *st.begin();
       cout << ans << nl;
   }
   
   else if(st.size() == 2){
       int prev = 0;
       for(auto &it : m){
           char xx;
           if(v[0] == it.second) xx = v[1];
           else xx = v[0];
           int x = it.first - prev;
           int soto = x/2;
           int boro = x - soto;
           int i;
           for(i = 0; i < boro; i++) ans+=it.second;
           
           for(i = 0; i < soto; i++) ans+=xx;
           prev = it.first;
       }
       if(ans.size() < n){
           while(ans.size()!=n){
               ans += last;
           }
       }
       cout << ans << nl;
   }
   
   else{
       
       int prev = 0;
       for(auto &it : m){
           char xx;
           if(v[0] == it.second) xx = v[1];
           else xx = v[0];
           int x = it.first - prev;
           int soto = x/2;
           int boro = x - soto;
           int prothom = soto/2;
           int ditio = soto - prothom;
           int i;
           for(i = 0; i < boro; i++) ans+=it.second;
           
           for(i = 0; i < prothom; i++) ans+=slast;
           for(i = 0; i <ditio; i++) ans+=last;
           prev = it.first;
       }
       if(ans.size() < n){
           while(ans.size()!=n){
               ans += last;
           }
       }
       cout << ans << nl;
       
   }
   
    
}
0