Submission #1233634

#TimeUsernameProblemLanguageResultExecution timeMemory
123363412baater말 (IOI15_horses)C++20
17 / 100
1595 ms8384 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 = x[0]; int secondLastMod = 0; ll secondLastModH = x[0]; 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; modCount = (horses*y[secondLastMod])/MOD; profit = (horses*y[secondLastMod])%MOD; for (int i = secondLastMod+1; 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...