| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 961733 | LucaLucaM | Horses (IOI15_horses) | C++17 | 1540 ms | 10444 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 <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
const int NMAX = 5e5;
const int mod = 1e9 + 7;
int n;
int x[NMAX + 1], y[NMAX + 1];
int solve() {
  ll prod = 1;
  bool bigProd = false;
  for (int i = 1; i <= n; i++) {
    if ((ll) prod * x[i] > 1e9) {
      bigProd = true;
      break;
    }
    prod *= x[i];
  }
  if (bigProd) {
    int m = n;
    int maxY = 0;
    while (m > 0 && x[m] == 1) {
      maxY = std::max(maxY, y[m--]);
    }
    prod = 1;
    for (int i = 1; i <= m; i++) {
      prod = (ll) prod * x[i] % mod;
    }
    return (ll) prod * maxY;
  }
  ll dp[n + 1] = {}; /// dp[i] =def= care e profitul maxim a.i. la finalul celei de a i-a zile am exact 1 cal
  for (int i = 1; i <= n; i++) {
    int intre = 1;
    for (int j = i; j > 0; j--) {
      intre *= x[j];
      dp[i] = std::max(dp[i], dp[j - 1] + (ll) y[i] * (intre - 1));
    }
  }
  ll ret = 0;
  for (int i = 1; i <= n; i++) {
    ret = std::max(ret, dp[i] + y[i]);
  }
  return ret;
}
int init(int N, int X[], int Y[]) {
  n = N;
  for (int i = 1; i <= n; i++) {
    x[i] = X[i - 1];
    y[i] = Y[i - 1];
  }
  return solve();
}
int updateX(int pos, int val) {
  x[++pos] = val;
  return solve();
}
int updateY(int pos, int val) {
  y[++pos] = val;
  return solve();
}
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... | ||||
