Submission #1114814

#TimeUsernameProblemLanguageResultExecution timeMemory
1114814KK_1729Nile (IOI24_nile)C++17
0 / 100
2059 ms20080 KiB
#include "nile.h" #include <bits/stdc++.h> using namespace std; // #define int long long #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define pb push_back #define all(a) a.begin(), a.end() #define endl "\n" void printVector(vector<int> a){ for (auto x: a) cout << x << " "; cout << endl; } int max(int x, int y){ if (x > y) return x; return y; } int maxi(vector<int> a){ int e = 0; for (auto x: a) e = max(e, x); return e; } std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A, std::vector<int> B, std::vector<int> E) { int Q = (int)E.size(); std::vector<long long> R(Q, 0); int n = (int) W.size(); vector<vector<int>> edges; // edge in the form of {diff, val, l, r} // auto comp = [] (int a, int b) { // return W[a] < W[b]; // }; vector<int> o; FOR(i,0,n) o.pb(i); // sort(all(o), comp); FOR(i,0,n-1){ edges.pb({W[o[i+1]]-W[o[i]], A[o[i]]+A[o[i+1]]-B[o[i]]-B[o[i+1]], i, i+1, 0}); if (i < n-2) edges.pb({W[o[i+2]]-W[o[i]], i+1, 1}); } sort(all(edges)); map<int, int> answers; vector<int> F = E; sort(all(F)); long long ans = 0; FOR(i,0,n) ans += A[i]; // int disc = 0; int u = edges.size(); vector<long long> even(n), odd(n); FOR(i,0,n){ odd[i] = A[i]-B[i]; } FOR(i,1,n-1){ even[i] = (A[i-1]-B[i-1])+(A[i]-B[i])+(A[i+1]-B[i+1]); } int curr = 0; set<pair<int, int>> intervals; for (auto X: F){ // cout << X << endl; while (curr < u){ if (edges[curr][0] <= X){ if (edges[curr][(int)edges[curr].size()-1] == 0){ // cout << "O" << endl; pair<int, int> current = {edges[curr][2], edges[curr][3]}; for (auto x: intervals){ if (x.second == edges[curr][2]){ current.first = x.first; intervals.erase(x); break; } } for (auto x: intervals){ if (x.first == current.second){ current.second = x.second; intervals.erase(x); break; } } // cout << "a" << current.first << current.second << endl; intervals.insert(current); }else{ int x = edges[curr][1]; even[x] -= (A[x-1]-B[x-1])+(A[x+1]-B[x+1]); } curr++; }else{ break; } } long long disc = 0; for (auto x: intervals){ long long m = 1e15; FOR(i,x.first,x.second+1){ disc += A[i]-B[i]; } if ((x.second-x.first)%2 == 1) break; FOR(i,x.first,x.second+1){ if ((i-x.first)%2 == 0){ m = min(m, odd[i]); }else{ m = min(m, even[i]); } } disc -= m; } answers[X] = ans-disc; // cout << "a" << intervals.size() << endl; // for (auto item: intervals){ // cout << item.first << item.second << endl; // } } FOR(i,0,Q){ R[i] = answers[E[i]]; } return R; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...