Submission #30507

# Submission time Handle Problem Language Result Execution time Memory
30507 2017-07-24T08:47:19 Z zoomswk Aliens (IOI16_aliens) C++14
0 / 100
0 ms 1848 KB
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> p;
int L[100005], R[100005];
long long dp[40005][5005];

void run(int l, int r, int opt_l, int opt_r, int lv){
    if(l > r) return;
    int mid = (l+r)>>1;
    int new_opt = -1;
    for(int x=opt_l; x<=min(opt_r, mid); x++){
        long long cst = dp[x-1][lv-1]+1LL*(R[mid]-L[x]+1)*(R[mid]-L[x]+1)-(R[x-1]-L[x]+1 > 0 ? 1LL*(R[x-1]-L[x]+1)*(R[x-1]-L[x]+1): 0LL);
        if(cst < dp[mid][lv]){
            dp[mid][lv] = cst;
            new_opt = x;
        }
    }
    run(l, mid-1, opt_l, new_opt, lv);
    run(mid+1, r, new_opt, opt_r, lv);
    return;
}

long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){
    for(int i=0; i<n; i++) p.push_back({min(r[i], c[i]), -max(r[i], c[i])});
    sort(p.begin(), p.end());
    int N=1, tmp_mx=-1;
    for(int i=0; i<n; i++){
        if(-p[i].second > tmp_mx){
            L[N] = p[i].first, R[N] = -p[i].second;
            tmp_mx = -p[i].second;
            N++;
        }
    }
    N--;
    R[0] = -1e9;
    for(int i=0; i<=N; i++) for(int j=0; j<=k; j++) dp[i][j] = 1e18;
    dp[0][0] = 0;
    for(int i=1; i<=N; i++) dp[i][1] = 1LL*(R[i]-L[1]+1)*(R[i]-L[1]+1);
    for(int i=2; i<=k; i++) run(1, N, 1, N, i);
    return dp[N][min(N, k)];
}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 1848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -