Submission #302223

#TimeUsernameProblemLanguageResultExecution timeMemory
302223square1001Horses (IOI15_horses)C++14
17 / 100
1578 ms10348 KiB
#include "horses.h" #include <queue> #include <vector> #include <cassert> #include <iostream> #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 = -1; while(!que.empty()) { u = que.top(); que.pop(); if(que.empty() || u != que.top()) break; } mult *= X[u]; if(X[u] >= 2) { st.push_back(u); } if(mult > 1000000000) break; } bool flag = false; if(mult <= 1000000000 && st.back() != 0) { st.push_back(0); flag = true; } 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); } for(int i = 1; i < st.size(); ++i) { assert(st[i - 1] != st[i]); } long long ans = 0; mult = 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, mult * mx); if(i != int(st.size()) - 2) { mult *= X[st[i + 1]]; } if(i != 0 || flag) { que.push(st[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); for(int i = 0; i < N; ++i) { if(X[i] >= 2) { que.push(i); } } return solve(); } int updateX(int pos, int val) { X[pos] = val; que.push(pos); return solve(); } int updateY(int pos, int val) { Y[pos] = val; return solve(); }

Compilation message (stderr)

horses.cpp: In function 'int solve()':
horses.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int, std::allocator<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i = 1; i < st.size(); ++i) {
      |                 ~~^~~~~~~~~~~
#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...