# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708266 | Alihan_8 | Horses (IOI15_horses) | C++17 | 271 ms | 524288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "horses.h"
#define Flag false
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
//#define int long long
typedef long long ll;
const ll Mod = 1e9+7;
vector <int> x, y;
bool chmax(int &x, int y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
int F(){
int n = (int)x.size();
const int N = 1e3+1, inf = 1e9;
vector <vector<int>> dp(n+1, vector <int> (N, -inf));
dp[0][1] = 0;
for ( int i = 0; i < n; i++ ){
for ( int j = 0; j < N; j++ ){
chmax(dp[i+1][j], dp[i][j]);
if ( j*x[i] >= N ) continue;
for ( int k = 0; k <= j*x[i]; k++ ){
chmax(dp[i+1][j*x[i]-k], k*y[i]+dp[i][j]);
}
}
}
return dp[n][0];
}
int init(int N, int X[], int Y[]) {
int n = N;
x.resize(n), y.resize(n);
for ( int i = 0; i < n; i++ ){
x[i] = X[i], y[i] = Y[i];
}
return F();
}
int updateX(int pos, int val){
x[pos] = val;
return F();
}
int updateY(int pos, int val){
y[pos] = val;
return F();
}
#if Flag
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
int X[n], Y[n];
for ( int i = 0; i < n; i++ ) cin >> X[i];
for ( int i = 0; i < n; i++ ) cin >> Y[i];
cout << init(n, X, Y) << ln;
int q; cin >> q;
while ( q-- ){
int type, l, r; cin >> type >> l >> r;
if ( type == 1 ) cout << updateX(l, r) << ln;
else cout << updateY(l, r) << ln;
}
cout << '\n';
/*
3
2 1 3
3 4 1
1
2 1 2
answer: {8, 6}
*/
}
#endif
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |