fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define fi first
  9. #define se second
  10. #define mp make_pair
  11. #define pb push_back
  12. #define fbo find_by_order
  13. #define ook order_of_key
  14.  
  15. typedef long long ll;
  16. typedef pair<int,int> ii;
  17. typedef vector<int> vi;
  18. typedef long double ld;
  19. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  20. typedef set<int>::iterator sit;
  21. typedef map<int,int>::iterator mit;
  22. typedef vector<int>::iterator vit;
  23.  
  24. vector<vector<int> > vec;
  25. int a[20];
  26.  
  27. int main()
  28. {
  29. ios_base::sync_with_stdio(0); cin.tie(0);
  30. int n; cin >> n;
  31. int prod = 1;
  32. for(int i = 0; i < n; i++)
  33. {
  34. int x; cin >> x;
  35. a[i] = x;
  36. prod*=x;
  37. vec.pb(vi());
  38. for(int j = 0; j < x; j++)
  39. {
  40. int y; cin >> y;
  41. vec[i].pb(y);
  42. }
  43. }
  44. set<int> s;
  45. for(int i = 0; i < prod; i++)
  46. {
  47. int cur = i; int sum = 0;
  48. for(int j = 0; j < n; j++)
  49. {
  50. sum += vec[j][cur%a[j]];
  51. cur/=a[j];
  52. }
  53. s.insert(sum);
  54. }
  55. for(set<int>::iterator it = s.begin(); it != s.end(); it++)
  56. {
  57. cout << (*it) << ' ';
  58. }
  59. }
  60.  
Runtime error #stdin #stdout #stderr 1.88s 528896KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc