Submission #1004884

# Submission time Handle Problem Language Result Execution time Memory
1004884 2024-06-21T21:48:50 Z magikarp23 Horses (IOI15_horses) C++17
34 / 100
1500 ms 19948 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;

const int MAX_N = 500000 + 1;
const int MOD = 1000000007; // 10^9 + 7

int X_store[MAX_N];
int Y_store[MAX_N];
double log_X[MAX_N];
double log_cumsum[MAX_N];
int N_store;

void precompute_logs() {
    log_cumsum[0] = 0;
    for (int i = 0; i < N_store; i++) {
        log_X[i] = log(X_store[i]);
        log_cumsum[i + 1] = log_cumsum[i] + log_X[i];
    }
}

long long mod_pow(long long base, int exp) {
    long long result = 1;
    while (exp > 0) {
        if (exp & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        exp >>= 1;
    }
    return result;
}

int calc_max_profit() {
    precompute_logs();
    
    int best_index = 0;
    double max_value = log_cumsum[1] + log(Y_store[0]);
    
    for (int i = 1; i < N_store; i++) {
        double current_value = log_cumsum[i + 1] + log(Y_store[i]);
        if (current_value > max_value) {
            max_value = current_value;
            best_index = i;
        }
    }
    
    long long profit = 1;
    for (int i = 0; i <= best_index; i++) {
        profit = (profit * X_store[i]) % MOD;
    }
    profit = (profit * Y_store[best_index]) % MOD;
    
    return static_cast<int>(profit);
}

int init(int N, int X[], int Y[]) {
    N_store = N;
    for (int i = 0; i < N; i++) {
        X_store[i] = X[i];
        Y_store[i] = Y[i];
    }
    return calc_max_profit();
}

int updateX(int pos, int val) {
    X_store[pos] = val;
    return calc_max_profit();
}

int updateY(int pos, int val) {
    Y_store[pos] = val;
    return calc_max_profit();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 0 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6552 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 0 ms 6492 KB Output is correct
8 Correct 0 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 0 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 0 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6580 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 15 ms 6616 KB Output is correct
24 Correct 14 ms 6488 KB Output is correct
25 Correct 16 ms 6644 KB Output is correct
26 Correct 16 ms 6492 KB Output is correct
27 Correct 13 ms 6492 KB Output is correct
28 Correct 16 ms 6492 KB Output is correct
29 Correct 11 ms 6488 KB Output is correct
30 Correct 12 ms 6632 KB Output is correct
31 Correct 9 ms 6492 KB Output is correct
32 Correct 10 ms 6640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1593 ms 16024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6588 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 0 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6536 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 0 ms 6492 KB Output is correct
18 Correct 0 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 15 ms 6636 KB Output is correct
24 Correct 15 ms 6492 KB Output is correct
25 Correct 16 ms 6492 KB Output is correct
26 Correct 16 ms 6492 KB Output is correct
27 Correct 13 ms 6632 KB Output is correct
28 Correct 15 ms 6492 KB Output is correct
29 Correct 11 ms 6492 KB Output is correct
30 Correct 12 ms 6492 KB Output is correct
31 Correct 9 ms 6632 KB Output is correct
32 Correct 11 ms 6632 KB Output is correct
33 Execution timed out 1588 ms 19948 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 0 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6592 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6744 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6588 KB Output is correct
23 Correct 15 ms 6492 KB Output is correct
24 Correct 15 ms 6628 KB Output is correct
25 Correct 15 ms 6492 KB Output is correct
26 Correct 14 ms 6492 KB Output is correct
27 Correct 12 ms 6628 KB Output is correct
28 Correct 15 ms 6492 KB Output is correct
29 Correct 10 ms 6488 KB Output is correct
30 Correct 12 ms 6492 KB Output is correct
31 Correct 8 ms 6492 KB Output is correct
32 Correct 9 ms 6628 KB Output is correct
33 Execution timed out 1592 ms 18124 KB Time limit exceeded
34 Halted 0 ms 0 KB -