Advertisement
willy108

Partial 80

Jul 25th, 2024
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,q;
  5. long long x;
  6. int k;
  7. int a[21];
  8. vector<int> tempv;
  9.  
  10. struct node{
  11.     int c;
  12.     long long w;
  13.     int p;
  14.     int bag;
  15.     bool operator < (const node& b) const {
  16.         return w > b.w;
  17.     }
  18. };
  19.  
  20. int main()
  21. {
  22.     cin >> n;
  23.     cin >> k;
  24.     for(int i = 0; i < n-1; i++){
  25.         cin >> a[i];
  26.         //a[i]=a[i]%k;
  27.     }
  28.     long long graph[k+1];
  29.     for(int  i = 0; i < k; i++){
  30.         graph[i]=-1;
  31.     }
  32.     priority_queue<node> pq;
  33.    
  34.     //map<int, vector<int>> mp;
  35.     int mp[k][n];
  36.  
  37.     for(int i = 0; i < n-1; i++){
  38.         mp[0][i]=0;
  39.     }
  40.     pq.push({0,0,-1,0});
  41.  
  42.     while(!pq.empty()){
  43.         node t=pq.top();
  44.         pq.pop();
  45.  
  46.         int i = t.c;
  47.         if(graph[t.c]==-1){
  48.             if(t.p!=-1){
  49.                 //t.c
  50.                 for(int it = 0; it < n-1; it++){
  51.                     mp[t.c][it] = mp[t.p][it];
  52.                 }
  53.                 mp[t.c][t.bag]++;
  54.             }
  55.  
  56.             graph[t.c]=t.w;
  57.             for(int j = 0; j < n-1; j++){
  58.                 int temp = (a[j]+i)%k;
  59.                 //if(temp>=k) continue;
  60.                 pq.push({temp,t.w+a[j],i,j});
  61.             }
  62.         }
  63.     }
  64.  
  65.     cin >> q;
  66.     while(q--){
  67.         cin >> x;
  68.         //cout << x << endl;
  69.         long long mo=x%k;
  70.         if(graph[mo]<=x){
  71.             cout << "1" << endl;
  72.             cout << (x-graph[mo])/k << " ";
  73.             for(int i = 0; i < n-1; i++){
  74.                 cout << mp[mo][i] << " ";
  75.             }
  76.             cout << endl;
  77.            
  78.         }
  79.         else{
  80.             cout << "0" << endl;
  81.             for(int i = 0; i < n; i++){
  82.                 cout << "0 ";
  83.             }
  84.             cout << endl;
  85.         }
  86.     }
  87. }
  88.  
  89. //112102;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement