Submission #764857

#TimeUsernameProblemLanguageResultExecution timeMemory
764857ymmSightseeing in Kyoto (JOI22_kyoto)C++17
0 / 100
2077 ms1876 KiB
#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; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #define MIN(x, y) ((x)<(y)?(x):(y)) const int S = 600; const int N = 100'010+S; typedef int T; T A[N], B[N], Ar[N]; int n, m; T lft[N]; int pos; void mov(int k) { static T tmp[2][S]; tmp[0][0] = lft[0] + A[0]; Loop (i,1,k) { bool i2 = i&1, i1 = !(i&1); tmp[i2][0] = MIN(lft[i] + A[i], tmp[i1][0] + B[pos+1]); Loop (j,1,i) { tmp[i2][j] = MIN(tmp[i1][j-1] + Ar[n-i+j], tmp[i1][j] + B[pos+1+j]); } tmp[i2][i] = tmp[i1][i-1] + A[0]; } lft[0] = tmp[(k-1)&1][k-1]; Loop (i,k,n) { bool i2 = i&1, i1 = !(i&1); tmp[i2][0] = MIN(lft[i] + A[i], tmp[i1][0] + B[pos+1]); Loop (j,1,k) { tmp[i2][j] = MIN(tmp[i1][j-1] + Ar[n-i+j], tmp[i1][j] + B[pos+1+j]); } lft[i-k+1] = tmp[i2][k-1]; } Loop (i,n,n+k-1) { bool i2 = i&1, i1 = !(i&1); Loop (j,i-n+1,k) { tmp[i2][j] = MIN(tmp[i1][j-1] + Ar[n-i+j], tmp[i1][j] + B[pos+1+j]); } lft[i-k+1] = tmp[i2][k-1]; } pos += k; } int main() { cin.tie(0) -> sync_with_stdio(false); cin >> n >> m; Loop (i,0,n) { ll x; cin >> x; A[i] = x; Ar[n-i] = A[i]; } Loop (i,0,m) { ll x; cin >> x; B[i] = x; } Loop (i,0,n) lft[i] = B[0]*i; while (pos < m-1) mov(MIN(S, MIN(n, m-1-pos))); cout << (ll)lft[n-1] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...