結果
問題 |
No.3157 Nabeatsu
|
ユーザー |
|
提出日時 | 2025-05-23 17:16:31 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 803 bytes |
コンパイル時間 | 3,891 ms |
コンパイル使用メモリ | 275,900 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-05-23 17:16:38 |
合計ジャッジ時間 | 6,169 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include<bits/stdc++.h> using namespace std; void rem3(string &s){ int l=s.size(); for(int i=0;i<l;i++){ if(s[i]=='3'){ s[i]='2'; for(int j=i+1;j<l;j++){ s[j]='9'; } break; } } } bool check(string &s){ int ds=0; for(auto &nx : s){ ds+=(nx-'0'); } return ((ds%3)!=0); } void sub1(string &s){ int l=s.size(); for(int i=l-1;i>=0;i--){ if(s[i]>='1'){ s[i]--; for(int j=i+1;j<l;j++){ s[j]='9'; } break; } } reverse(s.begin(),s.end()); while(s.back()=='0'){s.pop_back();} reverse(s.begin(),s.end()); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; while(true){ rem3(s); if(check(s)){break;} sub1(s); } cout << s << "\n"; return 0; }