# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
524310 |
2022-02-09T03:50:58 Z |
tube5429 |
Kas (COCI17_kas) |
C++14 |
|
221 ms |
1880 KB |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define repp(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define eb emplace_back
#define pb push_back
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define rtn return
#define trav(it,v) for(auto&it:(v))
#define rsz resize
#define tcT template<class T
#define tcTU tcT,class U
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<str> vs;
typedef vector<pii> vpii;
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b) - begin(a)); }
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { // assert(x >= 0);
return x == 0 ? 0 : 31-__builtin_clz(x); }
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
constexpr bool onbit(int x, int i) { return x>>i&1; }
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; }
tcT> bool ckmax(T& a, const T& b) {
return b > a ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); }
tcTU> T fstTrue(T lo ,T hi, U f) {
hi++ ; assert(lo <= hi);
while(lo < hi) {
T mid = lo + (hi - lo)/2;
f(mid) ? hi = mid : lo = mid+1;
}
return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
lo--; assert(lo <= hi);
while(lo < hi) {
T mid = lo + (hi-lo+1)/2;
f(mid) ? lo = mid : hi = mid-1;
}
return lo;
}
tcT> void remDup(vector<T>& v) {
sort(all(v)); v.erase(unique(all(v)),end(v)); }
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void setPrec() { cout << fixed << setprecision(16); }
void setIO(str name = "") {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
setPrec();
if(sz(name)) {
freopen((name + ".inp").c_str(),"r",stdin);
freopen((name + ".out").c_str(),"w",stdout);
}
}
const int MX = 5e2+3, LIM = 1e5;
int N, dp[2][LIM*2+3];
vi C;
void solve() {
cin>>N;
C.rsz(N);
int sum = 0;
F0R(i,N) cin>>C[i], sum += C[i];
memset(dp,-0x3f,sizeof dp);
dp[0][LIM] = 0;
F0R(i,N) {
int cur = i&1, nxt = cur^1;
F0R(j,LIM*2+1) if(dp[cur][j]>=0) {
ckmax(dp[nxt][j+C[i]],dp[cur][j]);
ckmax(dp[nxt][j-C[i]],dp[cur][j]+C[i]);
ckmax(dp[nxt][j],dp[cur][j]);
}
}
cout << sum-dp[N&1][LIM] << "\n";
}
int main() {
setIO();
int t=1;
//cin>>t;
while(t-- > 0) solve();
return 0;
}
Compilation message
kas.cpp: In function 'void setIO(str)':
kas.cpp:124:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
124 | freopen((name + ".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kas.cpp:125:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
125 | freopen((name + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1856 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1856 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1868 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1860 KB |
Output is correct |
2 |
Correct |
3 ms |
1856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1856 KB |
Output is correct |
2 |
Correct |
7 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1868 KB |
Output is correct |
2 |
Correct |
8 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
1868 KB |
Output is correct |
2 |
Correct |
43 ms |
1864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
1868 KB |
Output is correct |
2 |
Correct |
93 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
1868 KB |
Output is correct |
2 |
Correct |
221 ms |
1864 KB |
Output is correct |