Submission #43038

# Submission time Handle Problem Language Result Execution time Memory
43038 2018-03-08T08:35:14 Z top34051 Aliens (IOI16_aliens) C++14
Compilation error
0 ms 0 KB
#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<ll,ll>
#define X first
#define Y second
const int maxn = 1e5 + 5;

struct line {
    ll m,c;
    line(ll _m = 0, ll _c = 0) {
        m = _m; c = _c;
    }
};

int n,m,k;
pii p[maxn];
int r[maxn], c[maxn];
ll dp[maxn][maxn];
line cht[maxn];

bool cmp(pii x, pii y) {
    if(x.X!=y.X) return x.X<y.X;
    return x.Y>y.Y;
}

ll p2(ll x) { return x*x; }

double cut(int x, int y) {
    if(x==0 || y==0) return -2e16;
    return (double)(cht[y].c-cht[x].c)/(cht[x].m-cht[y].m);
}

void solve() {
    for(int x=1;x<=n;x++) dp[x][0] = 1e13;
    for(int t=1;t<=k;t++) {
        int len = 0;
        for(int x=1;x<=n;x++) {
            cht[++len] = line(-2*r[x], p2(r[x]) + dp[x-1][t-1] - p2(max(0,c[x-1]-r[x])));
            while(len>=3 && cut(len-1,len)<=cut(len-2,len)) cht[len-1] = cht[len], len--;
            int l = 2, r = len, mid, pos = 1;
            while(l<=r) {
                int mid = (l+r)/2;
                if(cut(mid-1,mid)<=c[x]) pos = mid, l = mid+1;
                else r = mid-1;
            }
            dp[x][t] = cht[pos].m*c[x] + cht[pos].c + p2(c[x]);
//            printf("dp %d %d = %lld\n",x,t,dp[x][t]);
        }
    }
}

long long take_photos(int N, int M, int K, std::vector<int> R, std::vector<int> C) {
	n = N; m = M; k = K;
	//prep
	for(int i=0;i<n;i++) {
        p[i] = {R[i],C[i]};
        if(p[i].X>p[i].Y) swap(p[i].X,p[i].Y);
	}
	sort(p,p+n,cmp);
    ll cur = -1, sz = 0;
	for(int i=0;i<n;i++) {
        if(p[i].Y<=cur) continue;
        sz++;
        r[sz] = p[i].X; c[sz] = p[i].Y+1;
        cur = p[i].Y;
	}
	n = sz;
	solve();
    return dp[n][k];
}

Compilation message

aliens.cpp: In function 'void solve()':
aliens.cpp:43:33: warning: unused variable 'mid' [-Wunused-variable]
             int l = 2, r = len, mid, pos = 1;
                                 ^
/tmp/cctVqRTN.o: In function `solve()':
aliens.cpp:(.text+0xb0): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0xf4): relocation truncated to fit: R_X86_64_PC32 against symbol `k' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x124): relocation truncated to fit: R_X86_64_32S against symbol `r' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x13b): relocation truncated to fit: R_X86_64_32 against symbol `r' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x140): relocation truncated to fit: R_X86_64_32 against symbol `c' defined in .bss section in /tmp/cctVqRTN.o
/tmp/cctVqRTN.o: In function `take_photos(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
aliens.cpp:(.text+0x35a): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x360): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x366): relocation truncated to fit: R_X86_64_PC32 against symbol `k' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x376): relocation truncated to fit: R_X86_64_32 against symbol `p' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x3ba): relocation truncated to fit: R_X86_64_32S against symbol `p' defined in .bss section in /tmp/cctVqRTN.o
aliens.cpp:(.text+0x3c1): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status