Submission #360533

# Submission time Handle Problem Language Result Execution time Memory
360533 2021-01-28T04:44:02 Z talant117408 Meetings (IOI18_meetings) C++17
0 / 100
1 ms 364 KB
#include "meetings.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
    ll n = sz(H), q = sz(L);
    if(q*n > 5000*5000) exit(0);
    vector <ll> ans(q);
    for(int i = 0; i < q; i++){
        vector <ll> mx(n);
        ll sum = 0;
        int l = L[i], r = R[i];
        stack <pii> st;
        for(int j = l; j <= r; j++){
            ll cnt = 1;
            while(sz(st) && st.top().first <= H[j]){
                cnt += st.top().second;
                sum -= st.top().first*st.top().second;
                st.pop();
            }
            sum += H[j]*cnt;
            st.push(mp(H[j], cnt));
            mx[j] += sum;
        }
        while(sz(st)) st.pop();
        sum = 0;
        for(int j = r; j >= l; j--){
            ll cnt = 1;
            while(sz(st) && st.top().first <= H[j]){
                cnt += st.top().second;
                sum -= st.top().first*st.top().second;
                st.pop();
            }
            sum += H[j]*cnt;
            st.push(mp(H[j], cnt));
            mx[j] += sum;
        }
        
        ll res = 9e18;
        for(int j = l; j <= r; j++) res = min(res, mx[j]);
        ans[i] = res;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -