Submission #106437

#TimeUsernameProblemLanguageResultExecution timeMemory
106437tictaccatMeetings (IOI18_meetings)C++14
19 / 100
5584 ms1936 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; int Q,N; unordered_map<int,int> m; int c = 0; vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) { Q = L.size(); N = H.size(); auto sortH = H; sort(sortH.begin(),sortH.end()); for (auto h: sortH) { if (m.count(h) == 0) m[h] = c++; } vector<long long> C(Q,-1); for (int q = 0; q < Q; q++) { vector<ll> costLeft(R[q]-L[q]+1), costRight(R[q]-L[q]+1); vector<pair<ll,ll>> fromRight, fromLeft; //height,index for (int x = L[q]; x <= R[q]; x++) { costLeft[x-L[q]] = (x == L[q] ? 0 : costLeft[x-L[q]-1]); int cur = x-1; while (fromLeft.size() > 0 && fromLeft.back().first < H[x]) { costLeft[x-L[q]] -= fromLeft.back().first*(cur-fromLeft.back().second); // cout << costLeft[1] << "\n"; cur = fromLeft.back().second; fromLeft.pop_back(); } costLeft[x-L[q]] += (long long)H[x]*(x-cur); // cout << costLeft[x-L[q]] << "\n"; fromLeft.push_back(make_pair(H[x],cur)); } // cout << "\n"; for (int x = R[q]; x >= L[q]; x--) { costRight[x-L[q]] = (x == R[q] ? 0 : costRight[x-L[q]+1]); int cur = x+1; while (fromRight.size() > 0 && fromRight.back().first < H[x]) { costRight[x-L[q]] -= fromRight.back().first*(fromRight.back().second-cur); // cout << costRight[1] << "\n"; cur = fromRight.back().second; fromRight.pop_back(); } costRight[x-L[q]] -= (long long)H[x]*(x-cur); //cout << costRight[x-L[q]] << "\n"; fromRight.push_back(make_pair(H[x],cur)); } for (int x = L[q]; x <= R[q]; x++) { ll val = costRight[x-L[q]] + costLeft[x-L[q]] - H[x]; // cout << costLeft[x-L[q]] << " " << costRight[x-L[q]] << " " << H[x] << "\n"; //cout << costRight[x-1] << " " << costLeft[x] << " " << H[x] << " " << val << "\n"; C[q] = (C[q] == -1 ? val : min(C[q],val)); } //C[q] = ; //TODO } return C; }
#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...