結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー rinrion
提出日時 2026-08-30 16:19:08
言語 C++14
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,618 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,804 ms
コンパイル使用メモリ 246,776 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 16:19:28
合計ジャッジ時間 5,382 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
#define rep(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define repr(i, s, n) for (int i = (s); i >= (int)(n); --i)
#define sz(x) ((int)(x).size())
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
auto _ = []{ios::sync_with_stdio(false); cin.tie(nullptr); return 0;}();
const int INFI = 1 << 30;
const ll INFL = 1LL << 62;

int main() {
	string s;
	cin >> s;
	int n=sz(s);
	bool jdg = 1;
	if(s[0]-'0'>5){ // 60~99
		rep (i, 0, n){
			cout<<5;
		}
		cout << '\n';
		return 0;
	}

	for (auto x : s){ // 55~59
		if((x - '0')<5){
			jdg=0;
			break;
		}
	}
	if(jdg){
		rep (i, 0, n){
			cout<<5;
		}
		cout << '\n';
		return 0;
	}

	if((s[0] - '0'<=4)){ //10~49
		jdg = 1;
		for (auto x : s){
			if((x - '0')<4){ //10~43
				jdg=0;
				break;
			}
		}
		if(!jdg){
			rep (i, 0, n-1){
				cout<<5;
			}
			cout << '\n';
			return 0;
		}
	}
	string ans="";
	jdg=0;
	reverse (s.begin(), s.end());
	rep (i, 0, n){
		int m=(s[i]-'0');
		if(m==4)ans.push_back ('4');
		else if(m>=5)ans.push_back ('5');
		else{ //~3
			ans.push_back ('5');
			s[i+1]=(char)(((s[i+1]-'0')-1)+'0');
		}
	}
	reverse (ans.begin(), ans.end());
	cout << ans << '\n';
	return 0;
}
0