Submission #302168

#TimeUsernameProblemLanguageResultExecution timeMemory
302168square1001Horses (IOI15_horses)C++14
0 / 100
1577 ms10760 KiB
#include "horses.h" #include <queue> #include <vector> #include <algorithm> using namespace std; const int mod = 1000000007; int N; priority_queue<int> que; vector<int> X, Y; int solve() { long long mult = 1; vector<int> st = { N }; while(!que.empty()) { int u = que.top(); que.pop(); if(X[u] >= 2) { if(mult * X[u] > Y[N]) break; mult *= X[u]; st.push_back(u); } } st.push_back(!que.empty() ? que.top() : 0); reverse(st.begin(), st.end()); int ini = st[0]; int coeff = 1; for(int i = 0; i <= ini; ++i) { coeff = int(1LL * coeff * X[i] % mod); } long long ans = 0; int submult = 1; for(int i = 0; i < int(st.size()) - 1; ++i) { int mx = 0; for(int j = st[i]; j < st[i + 1]; ++j) { mx = max(mx, Y[j]); } ans = max(ans, 1LL * submult * mx); if(i + 2 != int(st.size())) { submult *= X[i]; } } ans = (ans % mod) * coeff % mod; return int(ans); } int init(int N_, int X_[], int Y_[]) { N = N_; X = vector<int>(X_, X_ + N); Y = vector<int>(Y_, Y_ + N); return solve(); } int updateX(int pos, int val) { if(val >= 2) que.push(pos); 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...