Submission #736140

#TimeUsernameProblemLanguageResultExecution timeMemory
736140marvinthangHolding (COCI20_holding)C++17
110 / 110
59 ms107240 KiB
/************************************* * author: marvinthang * * created: 05.08.2022 11:41:13 * *************************************/ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define div ___div #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define FULL(i) (MASK(i) - 1) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class T> print_op(vector <T>) { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; } template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.fi << ", " << u.se << ')'; } template <class A, class B> inline bool minimize(A &a, B b) { A eps = 1e-9; if (a > b + eps) { a = b; return true; } return false; } template <class A, class B> inline bool maximize(A &a, B b) { A eps = 1e-9; if (a + eps < b) { a = b; return true; } return false; } const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0); const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2}; const int MAX = 102; int N, L, R, K, A[MAX]; int F[MAX][MAX][MAX * MAX / 4]; int fL[MAX][MAX * MAX / 4]; int fR[MAX][MAX * MAX / 4]; void init(void) { cin >> N >> L >> R >> K; minimize(K, N * N / 4); for (int i = 1; i <= N; ++i) cin >> A[i]; } void process(void) { for (int i = L; i <= R; ++i) for (int j = 0; j < L; ++j) for (int k = 0; k <= K; ++k) { F[i][j][k] = F[i - 1][j][k] + A[i]; if (j) { minimize(F[i][j][k], F[i][j - 1][k]); if (k >= i - j) minimize(F[i][j][k], F[i - 1][j - 1][k - (i - j)] + A[j]); } } for (int i = L - 1; i <= R; ++i) { fL[i][0] = F[i][L - 1][0]; for (int k = 1; k <= K; ++k) fL[i][k] = min(fL[i][k - 1], F[i][L - 1][k]); } memset(F, 0, sizeof(F)); for (int i = R; i >= L; --i) for (int j = N + 1; j > R; --j) for (int k = 0; k <= K; ++k) { F[i][j][k] = F[i + 1][j][k] + A[i]; if (j <= N) { minimize(F[i][j][k], F[i][j + 1][k]); if (k >= j - i) minimize(F[i][j][k], F[i + 1][j + 1][k - (j - i)] + A[j]); } } for (int i = R + 1; i >= L; --i) { fR[i][0] = F[i][R + 1][0]; for (int k = 1; k <= K; ++k) fR[i][k] = min(fR[i][k - 1], F[i][R + 1][k]); } int res = 1e9; for (int i = L - 1; i <= R; ++i) for (int k = 0; k <= K; ++k) minimize(res, fL[i][k] + fR[i + 1][K - k]); cout << res << '\n'; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); file("coci1920_r4_holding"); init(); process(); // cerr << "Time elapsed: " << TIME << " s.\n"; return (0^0); }

Compilation message (stderr)

holding.cpp: In function 'int main()':
holding.cpp:22:69: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 | #define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:81:2: note: in expansion of macro 'file'
   81 |  file("coci1920_r4_holding");
      |  ^~~~
holding.cpp:22:103: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 | #define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:81:2: note: in expansion of macro 'file'
   81 |  file("coci1920_r4_holding");
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...