Guest User

Untitled

a guest
Apr 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. /*
  2.     Team Proof
  3.     IIT Delhi
  4.  
  5.     C++ Template
  6.  */
  7.  
  8.  
  9. #include <iostream>
  10. #include <cstdio>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <cassert>
  14. #include <string>
  15. #include <vector>
  16. #include <algorithm>
  17. #include <set>
  18. #include <map>
  19. #include <stack>
  20. #include <queue>
  21. #include <cstdlib>
  22. using namespace std;
  23.  
  24. #define s(T) scanf("%d", &T)
  25. #define sl(T) scanf("%lld", &T)
  26. #define fill(a, val) memset(a, val, sizeof(a))
  27. #define mp make_pair
  28.  
  29. struct matchNum {
  30.     string val;
  31.     int length;
  32.    
  33.     matchNum()
  34.     {
  35.         val = "";
  36.         length = 0;
  37.     }
  38.    
  39.     matchNum(string v, int l)
  40.     {
  41.         val = v;
  42.         length = l;
  43.     }
  44. };
  45.  
  46. bool operator<(matchNum m1, matchNum m2)
  47. {
  48.     return m1.length < m2. length || (m1. length == m2. length && m1. val < m2. val);
  49. }
  50.  
  51. int totalCases, testNum;
  52.  
  53. matchNum DPlarge[105], DPsmall[105];
  54. int N;
  55. vector <int> req;
  56.  
  57. void preprocess()
  58. {
  59.     for(int i = 0; i <= 100; i++)
  60.     {
  61.         DPlarge[i] = matchNum();
  62.         DPsmall[i] = matchNum();
  63.     }
  64.    
  65.     req.resize(10);
  66.    
  67.     req[0] = 6;
  68.     req[1] = 2;
  69.     req[2] = 5;
  70.     req[3] = 5;
  71.     req[4] = 4;
  72.     req[5] = 5;
  73.     req[6] = 6;
  74.     req[7] = 3;
  75.     req[8] = 7;
  76.     req[9] = 6;
  77.    
  78.     for(int i = 0; i < 100; i++) if(i!= 1)
  79.     {
  80.         for(int dig = 0; dig < 10; dig++)
  81.         {
  82.             int nxt = i + req[dig];
  83.             if(nxt <= 100)
  84.             {
  85.                 string x = ""; x.push_back('0'+dig);
  86.                
  87.                 string v1 = x.append(DPlarge[i].val);
  88.                 string v2 = x.append(DPsmall[i].val);
  89.                
  90.                 matchNum cons = matchNum(v1, DPlarge[i]. length+1);
  91.                
  92.                 if(DPlarge[nxt].length == 0 || DPlarge[nxt] < cons)
  93.                     DPlarge[nxt] = cons;
  94.                
  95.                 cons = matchNum(v2, DPsmall[i]. length+1);
  96.                 if(DPsmall[nxt].length == 0 || cons < DPsmall[nxt] )
  97.                     DPsmall[nxt] = cons;
  98.             }
  99.         }
  100.     }
  101.    
  102. }
  103.  
  104. bool input()
  105. {
  106.     s(N);
  107.     return true;
  108. }
  109.  
  110. void solve()
  111. {
  112.     matchNum small, large;
  113.     small = matchNum("", 110); large = matchNum();
  114.    
  115.     for(int dig = 1; dig < 10; dig++)
  116.     {
  117.         if(req[dig] <= N && req[dig] != N-1)
  118.         {
  119.             int nxt = N-req[dig];
  120.             string x = ""; x.push_back('0'+dig);
  121.            
  122.             string v1 = x.append(DPlarge[nxt].val);
  123.             string v2 = x.append(DPsmall[nxt].val);
  124.            
  125.             matchNum cons = matchNum(v1, DPlarge[nxt]. length + 1);
  126.             if(large < cons)
  127.                 large = cons;
  128.            
  129.             cons = matchNum(v2, DPsmall[nxt]. length + 1);
  130.             if(cons < small)
  131.                 small = cons;
  132.         }
  133.     }
  134.    
  135.     cout << small.val << " " << large.val << endl;
  136. }
  137.  
  138. int main()
  139. {
  140.     preprocess();
  141.     s(totalCases);
  142.     for(testNum = 1; testNum <= totalCases; testNum++)
  143.     {
  144.         if( !input())
  145.             break;
  146.         solve();
  147.     }
  148. }
Add Comment
Please, Sign In to add comment