Advertisement
Bualrond

Untitled

Dec 5th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. #for a in range(1, 10):
  2.     #for b in range(1, 10):
  3.         #for c in range(1, 10):
  4.             #for d in range(1, 10):
  5. a, b, c, d = map(int, input().split())
  6. '''
  7. ans1 = ''
  8.  
  9. #a, b, c, d = map(int, input().split())
  10. cnt = 0
  11. mx = 1 << (a + b)
  12. while(mx > cnt):
  13.    ca = 0
  14.    cb = 0
  15.    cc = 0
  16.    cd = 0
  17.    flag = False
  18.    for i in range(a + b):
  19.        if(cnt & (1 << i)):
  20.            cb += 1
  21.        else:
  22.            ca += 1
  23.        
  24.        if(i < a + b - 1):
  25.            if((3 << i) & cnt == (1 << i)):
  26.                cc += 1
  27.            elif((3 << i) & cnt == (2 << i)):
  28.                cd += 1
  29.        
  30.        if(ca > a or cb > b or cc > c or cd > d):
  31.            flag = True
  32.            break
  33.    if(flag or ca != a or cb != b or cc != c or cd != d):
  34.        cnt += 1
  35.        continue
  36.    for i in range(a + b - 1, -1, -1):
  37.        if((1 << i) & cnt):
  38.            ans1 += '9'
  39.        else:
  40.            ans1 += '3'
  41.    break
  42. else:
  43.    ans1 = (-1)
  44. '''
  45.  
  46. if(abs(c - d) > 1):
  47.     ls = (-1)
  48. else:
  49.     ls = '39' * c
  50.     if(c == d):
  51.         ls += '3'
  52.     if(c < d):
  53.         ls = '9' + ls + '3'
  54.    
  55.     c3 = ls.count('3')
  56.     c9 = ls.count('9')
  57.    
  58.     if(c3 > a or c9 > b):
  59.         nls = ''
  60.         for i in range(len(ls)):
  61.             if(ls[i] == '9'):
  62.                 nls += '3'
  63.             else:
  64.                 nls += '9'
  65.         ls = nls
  66.         c3, c9 = c9, c3
  67.    
  68.     if(c3 > a or c9 > b):
  69.         ls = (-1)
  70.     else:
  71.         p3 = 0
  72.         p9 = 0
  73.         for i in range(0, len(ls)):
  74.             if(ls[i] == '3'):
  75.                 p3 = i
  76.                 break
  77.         for i in range(len(ls) - 1, -1, -1):
  78.             if(ls[i] == '9'):
  79.                 p9 = i
  80.                 break
  81.         ls = ls[:p9] + '9' * (b - c9) + ls[p9:]
  82.         ls = ls[:p3] + '3' * (a - c3) + ls[p3:]
  83. print(ls)
  84. '''      
  85. if(ans1 != ls):
  86.    print(a, b, c, d)
  87.    print(ans1, ls)
  88. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement