# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
428228 | haxorman | Horses (IOI15_horses) | C++14 | 1591 ms | 98484 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 "horses.h"
#include "bits/stdc++.h"
using namespace std;
const int mxN = 5e5 + 7;
const int MOD = 1e9 + 7;
int n;
long long x[mxN], y[mxN];
map<pair<int,int>,long long> dp;
int rec(int i, long long horses) {
horses *= x[i];
if (i == n - 1) {
return (y[i] * horses) % MOD;
}
if (dp.count({i, horses})) {
return dp[{i, horses}];
}
long long sell = 0;
for (int j = 0; j <= horses; ++j) {
sell = max(sell, rec(i + 1, j) + y[i] * (horses - j)) % MOD;
}
dp[{i, horses}] = sell;
return sell;
}
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 0; i < n; ++i) {
x[i] = X[i];
y[i] = Y[i];
}
return rec(0, 1);
}
int updateX(int pos, int val) {
dp.clear();
x[pos] = val;
return rec(0, 1);
}
int updateY(int pos, int val) {
dp.clear();
y[pos] = val;
return rec(0, 1);
}
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... |