結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー 👑 amentorimaru
提出日時 2026-08-30 13:58:36
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 937µs
コード長 3,789 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,427 ms
コンパイル使用メモリ 330,412 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 13:58:52
合計ジャッジ時間 5,630 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:138:3: warning: control reaches end of non-void function [-Wreturn-type]
  138 |   };
      |   ^

ソースコード

diff #
raw source code

#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using mint2 = modint998244353;

#include <bit>
#include <cstdint>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <array>
#include <tuple>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>  
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <bitset>
#include <chrono>
#include <type_traits>
using namespace std;

using ll = long long;

#define FOR(i, a, b) for(ll i=(a); i<(b);i++)
#define REP(i, n) for(ll i=0; i<(n);i++)
#define ROF(i, a, b) for(ll i=(ll(b)-1); i>=(a);i--)
#define PER(i, n) for(ll i=ll(n)-1; i>=0;i--)
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector< pair<ll,ll> >;
using VVP = vector<vector<pair<ll,ll>>>;
#define all(i) begin(i),end(i)
#define SORT(i) sort(all(i))
#define EXISTBIT(x,i) (((x>>i) & 1) != 0)
#define MP(a,b) make_pair(a,b)
template<typename T = ll>
vector<T> read(size_t n) {
  vector<T> ts(n);
  for (size_t i = 0; i < n; i++) cin >> ts[i];
  return ts;
}

template<typename TV, const ll N> void read_tuple_impl(TV&) {}
template<typename TV, const ll N, typename Head, typename... Tail>
void read_tuple_impl(TV& ts) {
  get<N>(ts).emplace_back(*(istream_iterator<Head>(cin)));
  read_tuple_impl<TV, N + 1, Tail...>(ts);
}
template<typename... Ts> decltype(auto) read_tuple(size_t n) {
  tuple<vector<Ts>...> ts;
  for (size_t i = 0; i < n; i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts);
  return ts;
}

template<typename T> T det2(array<T, 4> ar) { return ar[0] * ar[3] - ar[1] * ar[2]; }
template<typename T> T det3(array<T, 9> ar) { return ar[0] * ar[4] * ar[8] + ar[1] * ar[5] * ar[6] + ar[2] * ar[3] * ar[7] - ar[0] * ar[5] * ar[7] - ar[1] * ar[3] * ar[8] - ar[2] * ar[4] * ar[6]; }
template<typename T> bool chmax(T& tar, T src) { return tar < src ? tar = src, true : false; }
template<typename T> bool chmin(T& tar, T src) { return tar > src ? tar = src, true : false; }
template<typename T> void inc(vector<T>& ar) { for (auto& v : ar) v++; }
template<typename T> void dec(vector<T>& ar) { for (auto& v : ar) v--; }
template<typename T> vector<pair<T, int>> id_sort(vector<T>& a) {
  vector<pair<T, int>> res(a.size());
  for (int i = 0; i < a.size(); i++)res[i] = MP(a[i], i);
  SORT(res);
  return res;
}

using val = ll; using func = ll;

val op(val a, val b) { return max(a, b); }
val e() { return -(1LL<<60); }
//val mp(func f, val a) { return MP(a.first + f * a.second, a.second); }
//func comp(func f, func g) { return f + g; }
//func id() { return 0; }


// Rook
ll dxr[4] = { 1,0,-1,0 };
ll dyr[4] = { 0,1,0,-1 };
// Bishop
ll dxb[4] = { -1,-1,1,1 };
ll dyb[4] = { -1,1,-1,1 };
// queen
ll dxq[8] = { 0,-1,-1,-1,0,1,1,1 };
ll dyq[8] = { -1,-1,0,1,1,1,0,-1 };

void solve() {
  string s;
  cin>>s;
  ll n=s.size();
  string ans;
  auto dfs=[&](auto self, ll id) -> bool{
    if(id==n){
      return true;
    }
    if(s[id]<'4'){
      if(id==0){
        REP(i,n-1)ans.push_back('5');
      }
      return false;
    }
    if(s[id]>'5'){
      REP(i,n-id){
        ans.push_back('5');
      }
      return true;;
    }
    if(s[id]=='4'){
      if(self(self,id+1)){
        ans.push_back('4');
        return true;
      }
      if(id==0){
        REP(i,n-1){
          ans.push_back('5');
        }
      }
      return false;
    }
    if(s[id]=='5'){
      if(self(self,id+1)){
        ans.push_back('5');
        return true;
      }
      REP(i,n-id-1){
        ans.push_back('5');
      }
      ans.push_back('4');
      return true;
    }    
  };
  dfs(dfs,0);
  reverse(all(ans));
  cout<<ans;
}


int main() {
  ll t = 1;
  //cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

0