Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2015
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <string>
  6. #include <math.h>
  7. #include <cmath>
  8. #include <set>
  9. #include <map>
  10. #include <cassert>
  11. #include <algorithm>
  12. #include <ctime>
  13. #include <iomanip>
  14. //#include <thread>
  15.  
  16. using namespace std;
  17.  
  18. #define mp make_pair
  19. #define sz size()
  20. #define all(x) x.begin(),x.end()
  21. #define forn(i,n) for (int i = 0; i<int(n); i++)
  22. typedef long long ll;
  23. typedef long double ld;
  24. typedef pair<int, int> ii;
  25. const int INF = 1e9 + 7;
  26. const ld EPS = 1e-14;
  27.  
  28. //#define DEBUG
  29. #ifdef DEBUG
  30.     #define PL(x) cout<<#x<<" = "<<x<<endl
  31.     #define PR(x) cout<<#x<<" = "<<x<<" "
  32. #else
  33.     #define PL(x) {}
  34.     #define PR(x) {}
  35. #endif
  36.  
  37. ll opt[] = { 0, 1, 1, 1, 2, 1, 2, 1, 1, 3 };
  38. ll len[] = { 0, 1, 1, 1, 2, 1, 2, 2, 2, 3 };
  39. ll dpows[20];
  40. void init(){
  41.     ll num = 1;
  42.     for (int i = 0; i<19; i++){
  43.         dpows[i] = num;
  44.         num *= 10ll;
  45.     }
  46. }
  47.  
  48. vector<ll> getDeg(ll w){
  49.     vector<ll> ans;
  50.     while (w > 0){
  51.         ans.push_back(w % 10ll);
  52.         w /= 10ll;
  53.     }
  54.     return ans;
  55. }
  56.  
  57. void solve(){
  58.     ll w,c;
  59.     ll numNote = 0, numWay = 1;
  60.     cin>>w>>c;
  61.     if (w % 1000ll != 0){
  62.         cout << 0 << endl;
  63.         return;
  64.     }
  65.     else{
  66.         w /= 1000ll;
  67.     }
  68.     vector<ll> wdeg = getDeg(w);
  69.     if (wdeg.sz > c+1){
  70.         ll num = (w % (dpows[c + 2]))/(dpows[c]);
  71.         if (num == 11){
  72.             numWay = 2ll;
  73.         }
  74.         ll kol = w / (dpows[c+1]);
  75.         kol *= 2ll;
  76.         numNote += kol;
  77.     }
  78.     c = min(c,(ll)wdeg.sz - 1ll);
  79.     while (c >= 0){
  80.         if (wdeg[c] == 0){
  81.             c--;
  82.             continue;
  83.         }
  84.         else{
  85.             numWay *= opt[wdeg[c]];
  86.             numNote += len[wdeg[c]];
  87.             c--;
  88.         }
  89.     }
  90.     cout << numNote << " " << numWay << endl;
  91. }
  92.  
  93. int main(){
  94. #ifdef DEBUG
  95.     freopen("input.txt", "r", stdin);
  96.     freopen("output.txt", "w", stdout);
  97. #endif 
  98.  
  99.     init();
  100.     int test;
  101.     cin >> test;
  102.     for (int i = 0; i < test; i++){
  103.         solve();
  104.     }
  105.  
  106. #ifdef DEBUG
  107.     cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
  108. #endif
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement