fork download
  1. #include <bits/stdc++.h>
  2. #include <math.h>
  3. using namespace std;
  4. using ll = long long;
  5. using ull = unsigned long long;
  6. #define el '\n'
  7. #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
  8. #define all(v) v.begin(), v.end()
  9. #define fixed(n) fixed << setprecision(n)
  10. const int d4x[4]={0, 1, 0, -1}, d4y[4]={1, 0, -1, 0};
  11. // const int d8x[8]={0, 1, 1, 1, 0, -1, -1, -1}, d8y[8]={1, 1, 0, -1, -1, -1, 0, 1};
  12. #define id(c) ((c) - 'a' + 1)
  13. #define ch(i) ((i) + 'a' - 1)
  14. template <typename T>
  15. void printv(const vector<T>& v) {
  16. for (const auto& x : v) cout << x << ' ';
  17. cout << '\n';
  18. }
  19.  
  20. void fileIO() {
  21. #ifndef ONLINE_JUDGE
  22. freopen("input.txt", "r", stdin);
  23. freopen("output.txt", "w", stdout);
  24. #endif
  25. }
  26. bool valid(string s) {
  27. char diff = s[1] - s[0];
  28. for (int i = 2; i < s.size(); i++)
  29. {
  30. if(s[i] - s[i-1] != diff) return false;
  31. }
  32. return true;
  33. }
  34. ll vtoll(vector<int> &v) {
  35. string s = "";
  36. for (int i = 0; i < v.size(); i++)
  37. {
  38. s += v[i] + '0';
  39. }
  40. return stoll(s);
  41. }
  42. void solve() {
  43. ll n; cin >> n;
  44. if(n < 100) return void(cout << n);
  45. string s = to_string(n);
  46. vector<int> v, temp;
  47.  
  48. for (int i = 0; i < s.size(); i++)
  49. {
  50. v.push_back(s[i] - '0');
  51. }
  52. vector<ll> st;
  53. for (int i = 0; i < 5; i++)
  54. {
  55. for (int w = 0; w < 10; w++)
  56. {
  57. temp.clear();
  58. for (int k = 0; k < s.size(); k++)
  59. {
  60. temp.push_back(w);
  61. }
  62. st.push_back(vtoll(temp));
  63. bool c = 1;
  64. for (int j = 1; j < temp.size(); j++)
  65. {
  66. temp[j] = i + temp[j-1];
  67. if(temp[j] > 9) c = 0;
  68. }
  69. if(c) {
  70. st.push_back(vtoll(temp));
  71. reverse(temp.begin(), temp.end());
  72. st.push_back(vtoll(temp));
  73. }
  74. }
  75. }
  76. sort(all(st));
  77. // printv(st);
  78. cout << *lower_bound(all(st), n);
  79.  
  80. }
  81.  
  82. int main() {
  83. fastio;
  84. fileIO();
  85. // int t; cin >> t;
  86. // while (t--)
  87. solve();
  88. }
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
Standard output is empty