답안 #961737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961737 2024-04-12T11:39:35 Z LucaLucaM 말 (IOI15_horses) C++17
17 / 100
1500 ms 12180 KB
#include "horses.h"
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

#define int 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--]);
    }
    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 % mod;
}

signed init(signed N, signed X[], signed Y[]) {
  n = N;
  for (int i = 1; i <= n; i++) {
    x[i] = X[i - 1];
    y[i] = Y[i - 1];
  }
  return solve();
}

signed updateX(signed pos, signed val) {
  x[++pos] = val;
  return solve();
}

signed updateY(signed pos, signed val) {
  y[++pos] = val;
  return solve();
}

Compilation message

horses.cpp: In function 'll solve()':
horses.cpp:21:19: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   21 |     if ((ll) prod * x[i] > 1e9) {
      |         ~~~~~~~~~~^~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:64:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   64 |   return solve();
      |          ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:69:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   69 |   return solve();
      |          ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:74:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   74 |   return solve();
      |          ~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Incorrect 1 ms 2396 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1519 ms 12180 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2404 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2656 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2408 KB Output is correct
12 Correct 1 ms 2400 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2400 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2404 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2400 KB Output is correct
21 Incorrect 1 ms 2396 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2580 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Incorrect 0 ms 2396 KB Output isn't correct
22 Halted 0 ms 0 KB -