#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e3;
vector<int> t(4 * N) , lz(4 * N);
void push(int u){
t[u * 2] += lz[u];
t[u * 2 + 1] += lz[u];
lz[u * 2] += lz[u];
lz[u * 2 + 1] += lz[u];
lz[u] = 0;
}
void make_new(int n){
function<void(int , int , int)> build = [&](int u , int l , int r){
lz[u] = t[u] = 0;
if(l == r) return;
int m = (l + r) / 2;
build(u * 2 , l , m);
build(u * 2 + 1 , m + 1 , r);
};
build(n , 0 , n - 1);
}
void pos_assign(int u , int l , int r , int pos , int val){
if(l == r){
t[u] = val;
return;
}
push(u);
int m = (l + r) / 2;
if(pos <= m) pos_assign(u * 2 , l , m , pos , val);
else pos_assign(u * 2 + 1 , m + 1 , r , pos , val);
t[u] = max(t[u * 2] , t[u * 2 + 1]);
}
void range_add(int u , int l , int r , int L , int R , int val){
if(l > r || r < L || l > R) return;
if(L <= l && r <= R){
t[u] += val;
lz[u] += val;
return;
}
push(u);
int m = (l + r) / 2;
range_add(u * 2 , l , m , L , R , val);
range_add(u * 2 + 1 , m + 1 , r , L , R , val);
t[u] = max(t[u * 2] , t[u * 2 + 1]);
}
int get_max(int u , int l , int r , int L , int R){
if(l > r || r < L || l > R) return 0;
if(L <= l && r <= R) return t[u];
push(u);
int m = (l + r) / 2;
return max(get_max(u * 2 , l , m , L , R) , get_max(u * 2 + 1 , m + 1 , r , L , R));
}
void pos_assign(int pos , int val , int n){
pos_assign(1 , 0 , n - 1 , pos , val);
}
void range_add(int l , int r , int val , int n){
range_add(1 , 0 , n - 1 , l , r , val);
}
int get_max(int l , int r , int n){
if(r < l) return 0LL;
return get_max(1 , 0 , n - 1 , l , r);
}
main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n , m;cin >> n >> m;
vector<int> d1(N) , d2(N) , sz(N);
vector<int> f[2];
vector<vector<vector<pair<int , int>>>> cost(2 , vector<vector<pair<int , int>>>((n + m + 100) / 2));
for(int i = 0;i < n + m - 1;i ++){
cin >> d1[i];
f[i % 2].push_back(d1[i]);
if(i < min(n , m)) sz[i] = i + 1;
if(min(n , m) <= i && i < max(n , m)) sz[i] = sz[i - 1];
if(i >= max(n , m)) sz[i] = sz[i - 1] - 1;
}
int parity;
for(int i = 0;i < n + m - 1;i ++){
cin >> d2[i];
int st = abs(m - i - 1);
if(i % 2 == 0) parity = st % 2;
st /= 2;/*
cout << i << " " << st << " " << st + sz[i] - 1 << " " << parity << endl;*/
cost[i % 2][st + sz[i] - 1].push_back({d2[i] , st});
}
int ans = 0;
for(int w = 0;w < 2;w ++){
int par = (parity ^ (w == 1)) , all_cost = 0 , N = (int)f[w].size() + 1;/*
cout << "par W: " << w << " par: " << par << endl; */
make_new(N);/*
cout << "SZ: " << N << endl;*/
for(int i = 0;i < N;i ++){
int all = get_max(0 , i - 1 , N);
pos_assign(i , all + f[w][i] , N);
for(int k = 0;k < cost[par][i].size();k ++){
int end = cost[par][i][k].second;
int Cost = -cost[par][i][k].first;
range_add(end , i , Cost , N);
}
all_cost += f[w][i];
}/*
cout << "MN: ";
cout << get_max(0 , N - 1 , N) << endl;*/
ans += all_cost - max(0LL , get_max(0 , N - 1 , N));
}
cout << ans << endl;
}
Compilation message
colouring.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
74 | main(){
| ^~~~
colouring.cpp: In function 'int main()':
colouring.cpp:106:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int k = 0;k < cost[par][i].size();k ++){
| ~~^~~~~~~~~~~~~~~~~~~~~
colouring.cpp:99:7: warning: 'parity' may be used uninitialized in this function [-Wmaybe-uninitialized]
99 | int par = (parity ^ (w == 1)) , all_cost = 0 , N = (int)f[w].size() + 1;/*
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
10288 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
19808 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |