fork download
  1. //Author : Ujjawal Dixit , ABV-IIITM
  2. //Task : test
  3.  
  4. #include <bits/stdc++.h>
  5. #define MOD 1000000007
  6. #define MAX 1e9
  7. #define MIN -1e9
  8. using namespace std;
  9. typedef double ld;
  10. typedef long long ll;
  11. typedef vector<int> vi;
  12. typedef vector<vi> vvi;
  13. typedef pair<int,int> ii;
  14. #define FOR(i,n,m) for(int i=0;i<n;i+=m)
  15. #define For(i,n,m) for(int i=1;i<=n;i+=m)
  16. #define max(a,b) (a>=b?a:b)
  17. #define min(a,b) (a<b?a:b)
  18. #define countbits(num) __builtin_popcount(num)
  19. #define countbitsll(num) __builtin_popcountll(num)
  20. #define s(a) scanf("%d",&a)
  21. #define sll(a) scanf("%lld",&a)
  22. #define p(a) printf("%d",a)
  23. #define pll(a) printf("%lld",a)
  24. #define pln() printf("\n")
  25. #define getstr(in) getline(cin,in)
  26. #define getc() getchar()
  27. #define uj() int t; scanf("%d",&t); while(t--)
  28. ll mpow(ll a, ll n)
  29. {ll ret=1;ll b=a;while(n) {if(n&1)
  30. ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
  31. return (ll)ret;}
  32. template<typename T> T gcd(T a, T b) {
  33. if(!b) return a;
  34. return gcd(b, a % b);
  35. }
  36. template<typename T> T lcm(T a, T b) {
  37. return a * b / gcd(a, b);
  38. }
  39.  
  40. vector<int> arr;
  41. int *chk_arr;
  42. void fn(long long c_in,long long d,long long v)
  43. {
  44. d=arr.size();
  45. double check=pow(c_in+1,d)-1;
  46. for(int i=0;i<=check;i++)
  47. {
  48. long long binary[d]={0};
  49. long long c=0;
  50. long long sum=0;
  51. int temp=i;
  52. while(temp)
  53. {
  54. binary[c++]=temp%(c_in+1);
  55. temp/=(c_in+1);
  56. }
  57. for(int k=0;k<d;k++)
  58. {
  59. if(binary[k]!=0)
  60. {
  61. sum+=(binary[k]*arr[k]);
  62. }
  63. }
  64. if(sum<=v)
  65. chk_arr[sum]=1;
  66.  
  67. }
  68. }
  69. int main() {
  70. int t;
  71. cin>>t;
  72. for(int cases=1;cases<=t;cases++)
  73. {
  74. long long c,d,v;
  75. cin>>c>>d>>v;
  76. //vector<int> arr(d);
  77.  
  78. arr.resize(d);
  79. chk_arr=(int*)malloc(sizeof(int)*v);
  80. for(long long i=0;i<d;i++)
  81. cin>>arr[i];
  82.  
  83. chk_arr[0]=1;
  84. long long count=0;
  85. // int curr_sum, i, j;
  86.  
  87.  
  88. while(1)
  89. {
  90. long long add=-1;
  91. fn(c,d,v);
  92.  
  93. for(long long i=0;i<=v;i++)
  94. {//cout<<"\ni "<<i<<" "<<chk_arr[i];
  95. if(chk_arr[i]!=1)
  96. {add=i;break;}
  97. }
  98. if(add==-1)
  99. break;
  100. else
  101. {arr.push_back(add);count++;}
  102. }
  103. // cout<<count<<"\n";
  104. cout<<"Case #"<<cases<<": "<<count<<"\n";
  105.  
  106. }
  107.  
  108.  
  109. return 0;
  110. }
Runtime error #stdin #stdout #stderr 0s 3232KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_fill_insert