#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
146 ms |
1236 KB |
Output is correct |
5 |
Correct |
6 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Execution timed out |
2077 ms |
1876 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |