Submission #1014337


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int Nmax = 5005;
const long long inf = (1LL<<62);

int i, j, n, k, curr;
struct interval
{
    int l, r, len;
    bool operator < (const interval &other) const
    {
        return len > other.len;
    }
} a[Nmax];
long long d[Nmax/2][Nmax/2][2], ans;

int main()
{
    //freopen("intervals.in", "r", stdin);
    //freopen("intervals.out", "w", stdout);

    scanf("%d", &n);
    for(i=1; i<=n; ++i) scanf("%d%d", &a[i].l, &a[i].r), a[i].len = a[i].l + a[i].r;

    if(n%2==0) ++n;
    sort(a+1, a+n+1);

    for(i=0; i<=n/2; ++i)
    for(j=0; j<=n/2; ++j)
        d[i][j][0] = d[i][j][1] = inf;

    d[0][0][0] = 0;

    for(i=0; i<=n/2; ++i)
    for(j=0; j<=n/2; ++j)
    for(k=0; k<=1; ++k)
    {
        curr = i+j+k+1;
        if(curr>n) continue;

        if(i<n/2) d[i+1][j][k] = min(d[i+1][j][k], d[i][j][k] + a[curr].r + 1LL*a[curr].len*i);
        if(j<n/2) d[i][j+1][k] = min(d[i][j+1][k], d[i][j][k] + a[curr].l + 1LL*a[curr].len*j);
        if(!k) d[i][j][1] = min(d[i][j][1], d[i][j][0] + 1LL*(n-1)/2*a[curr].len);
    }

    printf("%lld\n", d[n/2][n/2][1]);

    return 0;
}

Submission Info

Submission Time
Task F - Intervals
User Alexa2001
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1196 Byte
Status AC
Exec Time 170 ms
Memory 98048 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:24:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:25:84: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=n; ++i) scanf("%d%d", &a[i].l, &a[i].r), a[i].len = a[i].l + a[i].r;
                                                                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 2
AC × 45
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 169 ms 98048 KB
001.txt AC 39 ms 21760 KB
002.txt AC 169 ms 98048 KB
003.txt AC 138 ms 82304 KB
004.txt AC 168 ms 98048 KB
005.txt AC 71 ms 42240 KB
006.txt AC 168 ms 98048 KB
007.txt AC 91 ms 54144 KB
008.txt AC 170 ms 98048 KB
009.txt AC 21 ms 11776 KB
010.txt AC 169 ms 98048 KB
011.txt AC 79 ms 46848 KB
012.txt AC 168 ms 98048 KB
013.txt AC 18 ms 9856 KB
014.txt AC 169 ms 98048 KB
015.txt AC 39 ms 22016 KB
016.txt AC 169 ms 98048 KB
017.txt AC 135 ms 80768 KB
018.txt AC 169 ms 98048 KB
019.txt AC 87 ms 51456 KB
020.txt AC 3 ms 256 KB
021.txt AC 3 ms 256 KB
022.txt AC 169 ms 98048 KB
023.txt AC 170 ms 98048 KB
024.txt AC 169 ms 98048 KB
025.txt AC 169 ms 98048 KB
026.txt AC 168 ms 98048 KB
027.txt AC 170 ms 98048 KB
028.txt AC 169 ms 98048 KB
029.txt AC 169 ms 98048 KB
030.txt AC 169 ms 98048 KB
031.txt AC 168 ms 98048 KB
032.txt AC 170 ms 98048 KB
033.txt AC 169 ms 98048 KB
034.txt AC 169 ms 98048 KB
035.txt AC 169 ms 98048 KB
036.txt AC 169 ms 98048 KB
037.txt AC 169 ms 98048 KB
038.txt AC 168 ms 98048 KB
039.txt AC 169 ms 98048 KB
040.txt AC 169 ms 98048 KB
041.txt AC 169 ms 98048 KB
042.txt AC 168 ms 98048 KB
example0.txt AC 3 ms 256 KB
example1.txt AC 3 ms 256 KB