Submission #1000921


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 1794 Byte
Status WA
Exec Time 488 ms
Memory 93696 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
AC × 2
AC × 44
WA × 1
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 488 ms 93568 KB
001.txt AC 90 ms 27136 KB
002.txt AC 472 ms 93568 KB
003.txt WA 359 ms 75264 KB
004.txt AC 476 ms 93568 KB
005.txt AC 184 ms 44800 KB
006.txt AC 478 ms 93568 KB
007.txt AC 235 ms 54144 KB
008.txt AC 477 ms 93568 KB
009.txt AC 48 ms 17024 KB
010.txt AC 477 ms 93568 KB
011.txt AC 203 ms 48512 KB
012.txt AC 476 ms 93568 KB
013.txt AC 41 ms 14976 KB
014.txt AC 473 ms 93568 KB
015.txt AC 92 ms 27264 KB
016.txt AC 473 ms 93568 KB
017.txt AC 356 ms 74368 KB
018.txt AC 472 ms 93568 KB
019.txt AC 222 ms 52096 KB
020.txt AC 2 ms 256 KB
021.txt AC 2 ms 256 KB
022.txt AC 475 ms 93696 KB
023.txt AC 473 ms 93568 KB
024.txt AC 470 ms 93568 KB
025.txt AC 472 ms 93568 KB
026.txt AC 472 ms 93568 KB
027.txt AC 472 ms 93568 KB
028.txt AC 475 ms 93568 KB
029.txt AC 476 ms 93568 KB
030.txt AC 476 ms 93696 KB
031.txt AC 475 ms 93568 KB
032.txt AC 474 ms 93568 KB
033.txt AC 473 ms 93568 KB
034.txt AC 476 ms 93568 KB
035.txt AC 469 ms 93568 KB
036.txt AC 474 ms 93568 KB
037.txt AC 473 ms 93568 KB
038.txt AC 473 ms 93568 KB
039.txt AC 476 ms 93568 KB
040.txt AC 479 ms 93568 KB
041.txt AC 478 ms 93568 KB
042.txt AC 471 ms 93568 KB
example0.txt AC 2 ms 256 KB
example1.txt AC 3 ms 384 KB