Submission #925171

#TimeUsernameProblemLanguageResultExecution timeMemory
925171heavylightdecompTriple Jump (JOI19_jumps)C++17
0 / 100
18 ms10032 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second using pii = pair<int,int>; #define pb push_back #define vt vector #define f0r(i,a,b) for(auto i = (a); i != (b);i++) #define r0f(i,a,b) for(auto i=(a);i>=(b);i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) // sim dor ris eni(x) rge rage dud debug 2eni 2dor #define sim template<class c #define dor > debug& operator<< #define ris return *this #define eni(x) sim> typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) sim> struct rge { c b,e; }; sim> rge<c> range(c i, c j) { return rge<c>{i,j}; } sim> auto dud(c* x)->decltype(cout <<*x, 0); sim> char dud(...); struct debug { ~debug() { cerr << endl; } eni(!=) { cerr << boolalpha << i; ris; } eni(==) { ris << range(all(i)); } sim, class b dor(pair<b,c> d) { ris << "(" << d.X << ", " << d.Y << ")"; } sim dor(rge<c> d) { *this << "{"; f0r(i,d.b,d.e) *this << ", " + 2*(i==d.b) << *i; ris << "}"; } }; #define imie(r...) " [" << #r << ": " << (r) << "] " //i only matches with nge(i) //sweepline //basic subtraction signed main() { cin.tie(0)->sync_with_stdio(0); int N; cin >> N; int idc; vt<int> ar(N), nge(N, -1), pge(N, -1); f0r(i,0,N) cin >> ar[i]; cin >> idc >> idc >> idc; stack<int> non; f0r(i,0,N) { while(non.size() and ar[non.top()] <= ar[i]) { nge[non.top()] = i; non.pop(); } non.push(ar[i]); } while(non.size()) non.pop(); r0f(i,N-1,0) { while(non.size() and ar[non.top()] < ar[i]) { pge[non.top()] = i; non.pop(); } non.push(ar[i]); } vt<pii> imp; f0r(i,0,N) { if(nge[i] != -1) imp.pb({i,nge[i]}); if(pge[i] != -1) imp.pb({pge[i],i}); } vt<int> suf(N,0); for(auto &[l,r] : imp) { //BUG: could be out of bounds if(r+r-l < N) suf[r+r-l] = max(suf[r+r-l], ar[l] + ar[r]); } int res = 0; f0r(i,1,N) { suf[i] = max(suf[i], suf[i-1]); res = max(res, suf[i] + ar[i]); } cout << res << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...