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>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ll long long
template<typename T>
void dbg_out(const T& t){
cout<<t<<endl;
}
template<typename T,typename... Args>
void dbg_out(const T& t,const Args&... args){
cout<<t<<" , ";
dbg_out(args...);
}
#define dbg(...) cout<<"("<<#__VA_ARGS__<<"): ";dbg_out(__VA_ARGS__);
const int mod=1e9+7;
const int maxn=2000;
int n;
vector<ll> x;
vector<ll> y;
ll dp[maxn];
ll solve(int i){
if(i>=n) return 0LL;
if(dp[i]!=-1) return dp[i];
ll h=1;
ll &ans=dp[i];
ans=0;
for(int k=i;k<n;k++){
h=(h%mod*x[k]%mod)%mod;
ans=max(ans,((ll)solve(k+1)%mod+(ll)(h-1)%mod*(ll)y[k]%mod)%mod);
ans=max(ans,((ll)h%mod*(ll)y[k]%mod)%mod);
}
ans%=mod;
return ans;
}
void clear(){
for(int j=0;j<=n;j++){
dp[j]=-1;
}
}
int init(int N, int X[], int Y[]) {
n=N;
x.resize(n,0);
y.resize(n,0);
for(int i=0;i<n;i++){
x[i]=X[i];
}
for(int i=0;i<n;i++){
y[i]=Y[i];
}
// clear();
memset(dp,-1,sizeof(dp));
return (int)((ll)solve(0)%mod);
}
int updateX(int pos, int val) {
x[pos]=val;
// clear();
memset(dp,-1,sizeof(dp));
return solve(0)%mod;
}
int updateY(int pos, int val) {
y[pos]=val;
clear();
return solve(0)%mod;
}
Compilation message (stderr)
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:61:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
61 | return solve(0)%mod;
| ~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:67:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
67 | return solve(0)%mod;
| ~~~~~~~~^~~~
# | 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... |