Submission #934499

#TimeUsernameProblemLanguageResultExecution timeMemory
934499TINKas (COCI17_kas)C++17
100 / 100
157 ms1784 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int INF = 2e9; void Task() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(9); if (fopen("test.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } } void Solve() { //Your Code int n; cin >> n; vector<int> dp1, dp2; dp1.resize(MAXN, INF); dp2.resize(MAXN); dp1[0] = 0; int sum = 0; for (int j = 0; j < n; j++) { int x; cin >> x; sum += x; dp2 = dp1; dp1.assign(dp1.size(), INF); for (int v = 0; v < MAXN; ++v) { if (x + v < MAXN) dp1[x + v] = min(dp1[x + v], dp2[v]); dp1[abs(v - x)] = min(dp1[abs(v - x)], dp2[v]); dp1[v] = min(dp1[v], dp2[v] + x); } } cout << (sum - dp1[0]) / 2 + dp1[0] << '\n'; } int main() { Task(); Solve(); cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms"; return 0; }

Compilation message (stderr)

kas.cpp: In function 'void Task()':
kas.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   freopen("test.inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
kas.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   freopen("test.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...
#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...