Advertisement
Dang_Quan_10_Tin

Đuôi gà

Sep 9th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #define NguyenDangQuan the_author
  2.  
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <stack>
  9. #include <set>
  10. #include <map>
  11. #include <cmath>
  12. #include <climits>
  13. #include <iomanip>
  14. #define all(x) x.begin(),x.end()
  15. #define mset(x, i) memset(x,i,sizeof(x))
  16. #define elif else if
  17. #define heap priority_queue
  18. #define fi first
  19. #define se second
  20. #define pb push_back
  21. #define ld long double
  22. #define ll long long
  23. #define ull unsigned long long
  24. #define task "cocktail"
  25. using namespace std;
  26.  
  27. int typetest;
  28.  
  29. inline void fastIOfileinput(){
  30.     ios_base:: sync_with_stdio(0);
  31.     cin.tie(0);
  32.     cout.tie(0);
  33.     if(fopen(task".inp", "r")){
  34.         freopen(task".inp", "r", stdin);
  35.         freopen(task".out", "w", stdout);
  36.     }
  37.     if(fopen(task".in", "r")){
  38.         freopen(task".in", "r", stdin);
  39.         freopen(task".out", "w", stdout);
  40.     }
  41.     typetest = 0;
  42. }
  43.  
  44. const int N = 1e3 + 2;
  45. int n, k;
  46. int a[N];
  47. queue<int> s;
  48. bool ck[2001];
  49. int trace[2001];
  50. int ans[2001];
  51.  
  52. inline void Enter(){
  53.     cin >> n >> k;
  54.     for(int i = 1; i <= n; ++i)
  55.         cin >> a[i], a[i] -= k;
  56. }
  57.  
  58. void traces(int i){
  59.     if(i - a[trace[i]] == 0){
  60.         ++ans[trace[i]];
  61.         return;
  62.     }
  63.     ++ans[trace[i]];
  64.     traces(i  - a[trace[i]]);
  65. }
  66.  
  67. inline void solve(){
  68.     for(int i = 1; i <= n; ++i)
  69.         if(a[i] > -1){
  70.             s.push(a[i]);
  71.             trace[a[i]] = i;
  72.             ck[a[i]] = 1;
  73.         }
  74.     bool ok = 0;
  75.     while(!s.empty()){
  76.         int c = s.front();
  77.         s.pop();
  78.         if(c == 0)
  79.             {ok = 1; break;}
  80.         for(int i = 1; i <= n; ++i)
  81.             if(c + a[i] <= 2000 && c + a[i] > -1 && !ck[c + a[i]]){
  82.                 s.push(c + a[i]);
  83.                 ck[c + a[i]] = 1;
  84.                 trace[c + a[i]] = i;
  85.             }
  86.     }
  87.     if(!ok) cout << "NO";
  88.     else{
  89.         cout << "YES\n";
  90.         traces(0);
  91.         for(int i = 1; i <= n; ++i)
  92.             cout << ans[i] << " ";
  93.     }
  94. }
  95.  
  96. signed main(){
  97.     fastIOfileinput();
  98.     if(typetest){
  99.         int t;
  100.         cin >> t;
  101.         while(t--){
  102.             Enter();
  103.             solve();
  104.         }
  105.     }
  106.     else{
  107.         Enter();
  108.         solve();
  109.     }
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement