pranavsindura

1373E - Precomp Table

Nov 30th, 2020 (edited)
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. #define ld long double
  4. #define pi pair<int,int>
  5. #define all(x) x.begin(), x.end()
  6. #define allr(x) x.rbegin(), x.rend()
  7. #define sz(x) ((int)x.size())
  8. #define ln(x) ((int)x.length())
  9. #define mp make_pair
  10. #define pb push_back
  11. #define ff first
  12. #define ss second
  13. #define endl '\n'
  14. #define dbg(x) cout << #x << ": " << x << endl
  15. #define clr(x,v) memset(x, v, sizeof(x))
  16. #define dblout(x) cout << setprecision(x) << fixed;
  17. #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  18. using namespace std;
  19. const double eps = 1e-9;
  20. const double PI = acos(-1.0);
  21. const ll mod = 1e9 + 7;
  22. const int MAXN = 1e9 + 5;
  23.  
  24. int dig_sum(int x)
  25. {
  26.     int sum = 0;
  27.     while(x)
  28.         sum += x % 10, x /= 10;
  29.     return sum;
  30. }
  31.  
  32. int save[156][10];
  33.  
  34. void cp()
  35. {
  36.     for(int i = 0; i <= 155; i++)
  37.         for(int k = 0; k <= 9; k++)
  38.             save[i][k] = INT_MAX;
  39.     for(int i = 0; i < MAXN; i++)
  40.     {
  41.         int sum = dig_sum(i);
  42.         for(int k = 1; k <= 9; k++)
  43.         {
  44.             sum += dig_sum(i + k);
  45.             if(sum <= 150)
  46.                 save[sum][k] = min(save[sum][k], i);
  47.         }
  48.         // if(i % 10000000 == 0)
  49.         //     dbg(i);
  50.     }
  51.     // dbg("done");
  52.     cout << "{\n";
  53.     for(int i = 0; i <= 155; i++)
  54.     {
  55.         cout << "{";
  56.         for(int k = 0; k <= 9; k++)
  57.         {
  58.             if(save[i][k] == INT_MAX)
  59.                 save[i][k] = -1;
  60.             cout << save[i][k];
  61.             if(k < 9)
  62.                 cout << ", ";
  63.         }
  64.         cout << "}";
  65.         if(i < 155)
  66.             cout << ",";
  67.         cout << endl;
  68.     }
  69.     cout << "}\n";
  70. }
  71.  
  72. int main()
  73. {
  74.     // FASTIO;
  75.     int t;
  76.     t = 1;
  77.     // cin >> t;
  78.     while(t--)
  79.     {
  80.         cp();
  81.     }
  82.     return 0;
  83. }
  84.  
  85. /*
  86. // greedy, k = 0
  87.     cout << "k = 0\n";
  88.     for(int i = 1; i <= 150; i++)
  89.     {
  90.         string num;
  91.         int sum = i;
  92.         while(sum > 9)
  93.             num += '9', sum -= 9;
  94.         if(sum)
  95.             num += char(48 + sum);
  96.         reverse(all(num));
  97.         cout << i << ": " << num << endl;
  98.     }
  99. */
Add Comment
Please, Sign In to add comment