fork(1) download
  1. public String isFair(int n, int b, int[] upTo, int[] quantity) {
  2. int q = upTo.length;
  3. Item[] t = new Item[q+1];
  4. for(int i = 0; i < q; ++i) {
  5. t[i] = new Item();
  6. t[i].set(upTo[i], quantity[i]);
  7. }
  8. t[q] = new Item();
  9. t[q].set(b, n);
  10. Arrays.sort(t, new MyComparator());
  11. int prev_upTo = 0, prev_quan = 0;
  12. String YES = "fair";
  13. String NO = "unfair";
  14. boolean dp[][][] = new boolean[n+1][n+1][n+1];
  15. for(int i = 0; i <= n; ++i)
  16. for(int j = 0; j <= n; ++j)
  17. for(int k = 0; k <= n; ++k)
  18. dp[i][j][k] = false;
  19. dp[0][0][0] = true;
  20. for(int i = 0; i < q+1; ++i) {
  21. int limit[] = new int[3];
  22. limit[0]=limit[1]=limit[2]=0;
  23. for(int j = prev_upTo + 1; j <= t[i].upTo; ++j)
  24. ++limit[j%3];
  25. int quan = t[i].quantity - prev_quan; // how many in this interval
  26. if(quan < 0 || quan > limit[0]+limit[1]+limit[2])
  27. return NO;
  28. for(int zero = 0; zero <= limit[0]; ++zero)
  29. for(int one = 0; one <= limit[1]; ++one)
  30. for(int two = 0; two <= limit[2]; ++two)
  31. if(zero+one+two == quan)
  32. for(int x=0;x<=n/3;++x)
  33. for(int y=0;y<=n/3;++y)
  34. for(int z=0;z<=n/3;++z)
  35. if(x+y+z==prev_quan && dp[x][y][z])
  36. dp[x+zero][y+one][z+two] = true;
  37. prev_upTo = t[i].upTo;
  38. prev_quan = t[i].quantity;
  39. }
  40. if(dp[n/3][n/3][n/3]) return YES;
  41. return NO;
  42. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:5: error: expected unqualified-id before 'public'
     public String isFair(int n, int b, int[] upTo, int[] quantity) {
     ^
stdout
Standard output is empty