Submission #961749

# Submission time Handle Problem Language Result Execution time Memory
961749 2024-04-12T12:00:38 Z LucaLucaM Horses (IOI15_horses) C++17
17 / 100
1500 ms 12172 KB
#include "horses.h"
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;
typedef __int128_t i128;

#define int ll

const int NMAX = 5e5;
const int mod = 1e9 + 7;

int n;
int x[NMAX + 1], y[NMAX + 1];

int solve() {
  /**
  dp[i][h] =def= care e profitul maxim daca dupa i ani am h cai

dp[i][h * x[i]] max= dp[i - 1][h]
dp[i][h] max= dp[i][h + 1] + y[i]

daca am bucati consecutive cu x[i] = 1, le pot grupa intr o singura bucata cu y sa fie maximu tuturor y urilor

1 <= y[i] <= 1e9

daca pot obtine 1e9 cai => tot inmultesc pana ajung la un sufix care are doar 1 la final
pt sufix ala cu doar 1 iau y maxim
asta is destul de sigur ca e usor de optimizat pt O((n + m) log) sau cv

ok, acum ramane cazu in care produsu e < 1e9
imi compactez x = 1
am n <= 60

fie pref[i] =def= nr maxim de cai din primii i ani
pref[i] = x[1] * x[2] * ... * x[i]

oare e optim sa fac cv gen
daca vreau sa vand, vand tot mai putin 1
(si ma rog, la final de tot ii vand pe toti)


ok bun am dat copy paste la notepad

ideea e ca am facut prost cazu in care am produsu mare
totusi, pare sa fie bine cazu in care am produsu mic

ma uit la cel mai mic sufix cu produsu > 1e9 -> daca compactez 1 urile, o sa aiba lungimea cel mult 30 (2^30 > 1e9)
=>
trebuie sa iau unu dintre astea
fac suff[i] practic dinamica pt produsu mic
max{big * pref[i] * y[i] + suff[i]}
big * pref[i] * y[i] + suff[i] - big * pref[j] * y[j] - suff[j] =
big * (pref[i] * y[i] - pref[j] * y[i]) + (suff[i] - suff[j])

ok aparent e optim sa vand tot intr o zi

  **/

  ll prod = 1;
  ll ret = 0;
  for (int i = 1; i <= n; i++) {
    prod *= x[i];
    ret = std::max(ret, (ll) prod * y[i]);
  }
  return ret;
}

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 'int init(int, int*, int*)':
horses.cpp:77:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   77 |   return solve();
      |          ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:82:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   82 |   return solve();
      |          ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:87:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   87 |   return solve();
      |          ~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2496 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 0 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 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 0 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 1 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 2392 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 -
# Verdict Execution time Memory Grader output
1 Execution timed out 1552 ms 12172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 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 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 0 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 2392 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 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 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Incorrect 1 ms 2396 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 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 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 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 2648 KB Output is correct
21 Incorrect 1 ms 2392 KB Output isn't correct
22 Halted 0 ms 0 KB -