Submission #1233629

#TimeUsernameProblemLanguageResultExecution timeMemory
123362912baaterHorses (IOI15_horses)C++20
17 / 100
1593 ms8244 KiB
#include "horses.h"
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const ll MOD = 1E9 + 7;
const int MAXN = 500050;
int n;
vector<int> x(MAXN);
vector<int> y(MAXN);


int solve() {
    int lastMod = 0;
    ll lastModH = 1;
    int secondLastMod = 0;
    ll secondLastModH = 1;
    ll horses = 1;
    ll profit = 0;
    ll modCount = 0;
    ll auxMod = 0;
    for (int i = 0; i < n; i++) {
        horses *= x[i];
        if (horses > MOD) {
            secondLastModH = lastModH;
            secondLastMod = lastMod;
            lastMod = i;
            lastModH = horses%MOD;
            horses %= MOD;
        }
    }
    horses = secondLastModH;
    for (int i = secondLastMod; i < n; i++) {
        horses *= x[i];
        auxMod = (horses*y[i])/MOD;
        if (auxMod == modCount) {
            profit = max(profit, (horses*y[i])%MOD);
        } else if (auxMod > modCount) {
            modCount = auxMod;
            profit = (horses*y[i])%MOD;
        }
    }
    return profit%MOD;
}


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

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

int updateY(int pos, int val) {
    y[pos] = val;
	return solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...