fork download
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. const int N = 20;
  5. int dp[1<<N];
  6. int a[N];
  7. int n , x;
  8. int getSum(int mask){
  9. int sum = 0;
  10. for(int i = 0;i<n;i++){
  11. if(mask & (1<<i)){
  12. sum += a[i];
  13. }
  14. }
  15. return sum;
  16. }
  17. int solve(int mask){
  18. if(mask == ((1<<n) - 1)){
  19. return 0;
  20. }
  21. if(dp[mask]!=-1)
  22. return dp[mask];
  23. int ans = INT_MAX;
  24. int sum = getSum(mask);
  25. int rem = sum%x;
  26. int prev = sum/x + (rem > 0);
  27. for(int i = 0;i<n;i++){
  28. if(mask & (1<<i)) continue;
  29. int newSum = sum + a[i];
  30. int curr = (newSum/x) + ((newSum%x) > 0);
  31. ans = min(ans , (curr > prev) + solve(mask|(1<<i)));
  32. }
  33. dp[mask] = ans;
  34. return ans;
  35. }
  36. signed main(){
  37. ios_base::sync_with_stdio(0);
  38. cin.tie(0);cout.tie(0);
  39. memset(dp,-1,sizeof(dp));
  40. cin >> n >> x;
  41. for(int i = 0;i<n;i++){
  42. cin >> a[i];
  43. }
  44. cout<<solve(0);
  45. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include<bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include<bits/stdc++.h>
        ^
Main.java:2: error: illegal character: '#'
#define int long long
^
Main.java:4: error: class, interface, or enum expected
const int N = 20;
^
Main.java:5: error: class, interface, or enum expected
int dp[1<<N];
^
Main.java:6: error: class, interface, or enum expected
int a[N];
^
Main.java:7: error: class, interface, or enum expected
int n , x;
^
Main.java:8: error: class, interface, or enum expected
int getSum(int mask){
^
Main.java:10: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	^
Main.java:10: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	              ^
Main.java:10: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	                  ^
Main.java:13: error: class, interface, or enum expected
		}
		^
Main.java:16: error: class, interface, or enum expected
}
^
Main.java:20: error: class, interface, or enum expected
	}
	^
Main.java:23: error: class, interface, or enum expected
	int ans = INT_MAX;
	^
Main.java:24: error: class, interface, or enum expected
	int sum = getSum(mask);
	^
Main.java:25: error: class, interface, or enum expected
	int rem = sum%x;
	^
Main.java:26: error: class, interface, or enum expected
	int prev = sum/x + (rem > 0);
	^
Main.java:27: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	^
Main.java:27: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	              ^
Main.java:27: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	                  ^
Main.java:29: error: class, interface, or enum expected
		int newSum = sum + a[i];
		^
Main.java:30: error: class, interface, or enum expected
		int curr = (newSum/x) + ((newSum%x) > 0);
		^
Main.java:31: error: class, interface, or enum expected
		ans = min(ans , (curr > prev) + solve(mask|(1<<i)));
		^
Main.java:32: error: class, interface, or enum expected
	}
	^
Main.java:34: error: class, interface, or enum expected
	return ans;
	^
Main.java:35: error: class, interface, or enum expected
}
^
Main.java:38: error: class, interface, or enum expected
	cin.tie(0);cout.tie(0);
	^
Main.java:38: error: class, interface, or enum expected
	cin.tie(0);cout.tie(0);
	           ^
Main.java:39: error: class, interface, or enum expected
	memset(dp,-1,sizeof(dp));
	^
Main.java:40: error: class, interface, or enum expected
	cin >> n >> x;
	^
Main.java:41: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	^
Main.java:41: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	              ^
Main.java:41: error: class, interface, or enum expected
	for(int i = 0;i<n;i++){
	                  ^
Main.java:43: error: class, interface, or enum expected
	}
	^
Main.java:45: error: class, interface, or enum expected
}
^
36 errors
stdout
Standard output is empty