fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int N, L[55];
  5. //---------------------------------------------------------------------------------------------------
  6. int LL[55];
  7. int getsm(int a, int b) { // L[a] + L[a + 1] + ... + L[b]
  8. int sm = LL[b];
  9. if (a) sm -= LL[a - 1];
  10. return sm;
  11. }
  12. //---------------------------------------------------------------------------------------------------
  13. int memo[55];
  14. int f(int idx, int mi, int ma) {
  15. if (0 <= memo[idx]) return memo[idx];
  16. if (idx == N) return 1;
  17.  
  18. int lim = N;
  19. if (idx == 0) lim = N - 1;
  20. rep(i, idx, lim) {
  21. int sm = getsm(idx, i);
  22. if (mi <= sm and sm <= ma) {
  23. if (f(i + 1, mi, ma)) return memo[idx] = 1;
  24. }
  25. }
  26.  
  27. return memo[idx] = 0;
  28. }
  29. //---------------------------------------------------------------------------------------------------
  30. void _main() {
  31. cin >> N;
  32. rep(i, 0, N) cin >> L[i];
  33. LL[0] = L[0];
  34. rep(i, 1, N) LL[i] = LL[i - 1] + L[i];
  35.  
  36. vector<int> v;
  37. rep(i, 0, N) rep(j, i, N) {
  38. int sm = getsm(i, j);
  39. v.push_back(sm);
  40. }
  41. sort(all(v));
  42. v.erase(unique(all(v)), v.end());
  43.  
  44. int n = v.size();
  45. int ans = inf;
  46. rep(i, 0, n) rep(j, i, n) {
  47. int mi = v[i];
  48. int ma = v[j];
  49. rep(k, 0, N + 1) memo[k] = -1;
  50. if (f(0, mi, ma)) chmin(ans, ma - mi);
  51. }
  52. cout << ans << endl;
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int f(int, int, int)’:
prog.cpp:20:9: error: ‘i’ was not declared in this scope
     rep(i, idx, lim) {
         ^
prog.cpp:20:20: error: ‘rep’ was not declared in this scope
     rep(i, idx, lim) {
                    ^
prog.cpp: In function ‘void _main()’:
prog.cpp:32:9: error: ‘i’ was not declared in this scope
     rep(i, 0, N) cin >> L[i];
         ^
prog.cpp:32:16: error: ‘rep’ was not declared in this scope
     rep(i, 0, N) cin >> L[i];
                ^
prog.cpp:36:5: error: ‘vector’ was not declared in this scope
     vector<int> v;
     ^~~~~~
prog.cpp:36:12: error: expected primary-expression before ‘int’
     vector<int> v;
            ^~~
prog.cpp:41:14: error: ‘v’ was not declared in this scope
     sort(all(v));
              ^
prog.cpp:41:15: error: ‘all’ was not declared in this scope
     sort(all(v));
               ^
prog.cpp:41:16: error: ‘sort’ was not declared in this scope
     sort(all(v));
                ^
prog.cpp:42:26: error: ‘unique’ was not declared in this scope
     v.erase(unique(all(v)), v.end());
                          ^
prog.cpp:45:15: error: ‘inf’ was not declared in this scope
     int ans = inf;
               ^~~
stdout
Standard output is empty