Submission #647865

#TimeUsernameProblemLanguageResultExecution timeMemory
647865ymmHoliday (IOI14_holiday)C++17
100 / 100
4145 ms8240 KiB
#include"holiday.h" #include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x) #define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x) typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll , ll > pll; using namespace std; const int N = 100064; ll mxl[N*2], mxl2[N*2], mxr[N*2], mxr2[N*2]; ll mxc[N]; int bin(int len, ll x) { int l=1, r=len; while (l < r) { int mid = (l+r)/2; if (mxc[mid] - mxc[mid-1] >= x) l = mid+1; else r = mid; } return l; } __attribute__((optimize("O3,unroll-loops"),target("avx2"))) void insert(int len, ll x) { int i = bin(len, x); for (int j = len; j >= i; --j) mxc[j] = mxc[j-1] + x; } template<ll a[2*N]> __attribute__((optimize("O3,unroll-loops"),target("avx2"))) void up(int len, int off) { #define MAX(x, y) ((x)>(y)?(x):(y)) Loop (i,0,len) a[i+off] = MAX(a[i+off], mxc[i]); #undef MAX } long long int findMaxAttraction(int n, int s, int d, int attr[]) { int k = min(s, n-1-s); Loop (i,s+1,n) { insert(i - s, attr[i]); up<mxr>(i - s + 1, i - s); if (i-s <= k) up<mxr2>(i - s + 1, 2*(i - s)); } LoopR (i,0,s) { insert(s - i, attr[i]); up<mxl>(s - i + 1, s - i); if (s-i <= k) up<mxl2>(s - i + 1, 2*(s - i)); } Loop (i,0,2*N-1) { mxl [i+1] = max(mxl [i+1], mxl [i]); mxl2[i+1] = max(mxl2[i+1], mxl2[i]); mxr [i+1] = max(mxr [i+1], mxr [i]); mxr2[i+1] = max(mxr2[i+1], mxr2[i]); } ll ans = 0; Loop (i,0,d+1) { if (i < 2*N && (d-i) < 2*N) { ans = max(ans, mxl[i] + mxr2[d-i]); ans = max(ans, mxl2[i] + mxr[d-i]); } } Loop (i,0,d) { if (i < 2*N && (d-1-i) < 2*N) { ans = max(ans, mxl[i] + mxr2[d-1-i] + attr[s]); ans = max(ans, mxl2[i] + mxr[d-1-i] + attr[s]); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...