Submission #1000901


Source Code Expand

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

const int MN = 5050;
using P = pair<ll, ll>;
int n;
vector<P> v;

ll dp[MN][MN];
bool used[MN][MN];
ll calc(int m, int a) {
    if (m == 0) return 0;
    int b = n/2 - ((n-m)-(n/2-a));
    if (used[m][a]) return dp[m][a];
    used[m][a] = true;
    ll &ans = dp[m][a];
    ans = TEN(18);
    P p = v[m-1];
    // left
    if (a) {
        ll x = p.first*(a-1);
        x += p.second*(a);
        ans = min(ans, x + calc(m-1, a-1));
    }
    // right
    if (b) {
        ll x = p.first*(b);
        x += p.second*(b-1);
        ans = min(ans, x + calc(m-1, a));
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        v.push_back(P(l, r));
    }
    sort(v.begin(), v.end(), [&](const P l, const P r){
        return (l.first+l.second) > (r.first+r.second);
    });
    ll ans = 0;
    if (n % 2 == 1) {
        ans += (v[n-1].first+v[n-1].second)*n/2;
        v.pop_back();
        n--;
    }

//    for (auto d: v) {
//        cout << d.first << " " << d.second << endl;
//    }
    cout << ans + calc(n, n/2) << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Intervals
User yosupo
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1721 Byte
Status WA
Exec Time 490 ms
Memory 93568 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
AC × 2
AC × 39
WA × 6
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 484 ms 93568 KB
001.txt AC 94 ms 27136 KB
002.txt AC 483 ms 93568 KB
003.txt WA 369 ms 75264 KB
004.txt AC 485 ms 93568 KB
005.txt WA 187 ms 44800 KB
006.txt AC 483 ms 93568 KB
007.txt AC 240 ms 54144 KB
008.txt AC 484 ms 93568 KB
009.txt AC 51 ms 17024 KB
010.txt AC 483 ms 93568 KB
011.txt AC 210 ms 48640 KB
012.txt AC 483 ms 93568 KB
013.txt AC 42 ms 14976 KB
014.txt AC 484 ms 93568 KB
015.txt WA 97 ms 27264 KB
016.txt AC 484 ms 93568 KB
017.txt AC 361 ms 74240 KB
018.txt AC 487 ms 93568 KB
019.txt WA 226 ms 52096 KB
020.txt WA 3 ms 384 KB
021.txt WA 3 ms 256 KB
022.txt AC 484 ms 93568 KB
023.txt AC 485 ms 93568 KB
024.txt AC 485 ms 93568 KB
025.txt AC 486 ms 93568 KB
026.txt AC 484 ms 93568 KB
027.txt AC 484 ms 93568 KB
028.txt AC 490 ms 93568 KB
029.txt AC 485 ms 93568 KB
030.txt AC 479 ms 93568 KB
031.txt AC 482 ms 93568 KB
032.txt AC 481 ms 93568 KB
033.txt AC 484 ms 93568 KB
034.txt AC 486 ms 93568 KB
035.txt AC 485 ms 93568 KB
036.txt AC 485 ms 93568 KB
037.txt AC 485 ms 93568 KB
038.txt AC 484 ms 93568 KB
039.txt AC 484 ms 93568 KB
040.txt AC 483 ms 93568 KB
041.txt AC 484 ms 93568 KB
042.txt AC 483 ms 93568 KB
example0.txt AC 3 ms 256 KB
example1.txt AC 3 ms 384 KB