Submission #1115327

#TimeUsernameProblemLanguageResultExecution timeMemory
1115327gdragonBali Sculptures (APIO15_sculpture)C++17
0 / 100
1 ms504 KiB
#include <bits/stdc++.h> using namespace std; #define TASK "long" #define fi first #define se second #define ll long long #define pb push_back #define ALL(x) (x).begin(), (x).end() #define GETBIT(mask, i) ((mask) >> (i) & 1) #define MASK(i) ((1LL) << (i)) #define SZ(x) ((int)(x).size()) #define mp make_pair #define CNTBIT(mask) __builtin_popcount(mask) template<class X, class Y> bool maximize(X &x, Y y){ if (x < y) {x = y; return true;} return false;}; template<class X, class Y> bool minimize(X &x, Y y){ if (x > y) {x = y; return true;} return false;}; typedef pair<int, int> ii; const int N = 1e5 + 5; const long long INF = (long long)1e18 + 7; const int mod = 1e9 + 7; int n, A, B; vector<long long> f; vector<vector<long long>> dp; void read() { cin >> n >> A >> B; f.assign(n + 1, 0); for(int i = 1; i <= n; i++) { cin >> f[i]; f[i] += f[i - 1]; } } long long sum(int l, int r) { return f[r] - f[l - 1]; } void calDp(int l, int r, int optl, int optr) { if (l > r) return; int best = optl; int mid = (l + r) >> 1; for(int i = optl; i <= min(mid, optr); i++) { long long cost = INF; if (dp[1][i - 1] < INF) cost = dp[1][i - 1] | sum(i, mid); if (minimize(dp[0][mid], cost)) best = i; } calDp(l, mid - 1, optl, best); calDp(mid + 1, r, best, optr); } void solve() { dp.assign(2, vector<long long>(n + 1, INF)); dp[1][0] = 0; long long ans = INF; for(int i = 1; i <= B; i++) { fill(ALL(dp[0]), INF); calDp(1, n, 1, n); if (i >= A) ans = min(ans, dp[0][n]); swap(dp[0], dp[1]); } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } int test = 1; // cin >> test; while(test--) { read(); solve(); } return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...