Submission #1183375

#TimeUsernameProblemLanguageResultExecution timeMemory
1183375nagorn_phKas (COCI17_kas)C++20
90 / 100
2094 ms19036 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,fast-math,unsafe-math-optimizations") #pragma GCC target("avx2,popcnt,tune=native") #define int long long #define double long double #define pii pair <int,int> #define tiii tuple <int, int, int> #define f first #define s second #define all(x) x.begin(), x.end() #define ub(a, b) upper_bound(a.begin(), a.end(), b) - a.begin() #define lb(a, b) lower_bound(a.begin(), a.end(), b) - a.begin() #define ve vector #define graph(a, n) vector <int> a[n]; #define wgraph(a, n) vector <pii> a[n]; #define emb emplace_back #define em emplace #define ins insert #define er erase #define iShowSpeed cin.tie(NULL)->sync_with_stdio(false) using namespace std; template <typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>; const int mod = 1e9 + 7; const int inf = 1e18; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int32_t main(){ iShowSpeed; int n; cin >> n; vector <int> a(n); for (auto &e : a) cin >> e; unordered_map <int, int> dp; // dp[i] = max value we can have if kile has i more money than pogi dp[0] = 0; int sum = accumulate(all(a), 0ll); for (auto e : a) { unordered_map <int, int> temp = dp; for (int i = -sum; i <= sum; i++) { if (dp.find(i) != dp.end()) { temp[i + e] = max(temp[i + e], dp[i] + e); temp[i - e] = max(temp[i - e], dp[i] + e); } } dp = temp; } cout << sum - dp[0] / 2; }
#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...