Submission #426400

# Submission time Handle Problem Language Result Execution time Memory
426400 2021-06-13T23:55:27 Z ngrace Aliens (IOI16_aliens) C++14
12 / 100
180 ms 2448 KB
#include "aliens.h"
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <limits.h>
using namespace std;
#define v vector
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
 
int N,K;
v<pii> pos;
v<v<long long>> memo;
long long diagSolve(int cur, int k){//cover first cur with k photos
    if(memo[cur][k]!=-1) return memo[cur][k];
    if(cur==0) return memo[cur][k] = 0;
    if(k==0) return LLONG_MAX/2;

    long long ret=LLONG_MAX/2;
    for(int i=0;i<cur;i++){
        long long curArea=(pos[cur-1].se-pos[i].fi+1) * (pos[cur-1].se-pos[i].fi+1);
        //check for intersection with prev:
        if(i!=0){
            long long length = max(0, pos[i-1].se-pos[i].fi+1);
            curArea-=length*length;
        }

        long long take = diagSolve(i,k-1);

        if(take+curArea<ret) ret=take+curArea;
    }
    return memo[cur][k] = ret;
}

long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
    K=k;
    set<pii> tmp;
    for(int i=0;i<n;i++){
        tmp.insert({r[i],-c[i]});
    }
    for(pii it:tmp){
        if(pos.size()==0) {
            pos.push_back({it.fi,-it.se});
            continue;
        }
        if(it.fi<=pos.back().se && -it.se<=pos.back().se) continue;
        pos.push_back({it.fi,-it.se});
    }
    N=pos.size();
    memo=v<v<ll>>(N+1,v<long long>(k+1,-1));
    return diagSolve(N,k);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Incorrect 1 ms 204 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 1
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 1
4 Correct 1 ms 204 KB Correct answer: answer = 5
5 Correct 1 ms 204 KB Correct answer: answer = 41
6 Correct 1 ms 204 KB Correct answer: answer = 71923
7 Correct 2 ms 204 KB Correct answer: answer = 77137
8 Correct 71 ms 1124 KB Correct answer: answer = 764
9 Correct 1 ms 332 KB Correct answer: answer = 250000
10 Correct 180 ms 2448 KB Correct answer: answer = 500
11 Correct 1 ms 204 KB Correct answer: answer = 32
12 Correct 2 ms 340 KB Correct answer: answer = 130050
13 Correct 39 ms 460 KB Correct answer: answer = 5110
14 Correct 6 ms 332 KB Correct answer: answer = 2626
15 Correct 15 ms 496 KB Correct answer: answer = 796
16 Correct 27 ms 484 KB Correct answer: answer = 7580
17 Correct 89 ms 844 KB Correct answer: answer = 1904
18 Correct 1 ms 332 KB Correct answer: answer = 996004
19 Correct 15 ms 292 KB Correct answer: answer = 38817
20 Correct 50 ms 588 KB Correct answer: answer = 4096
21 Correct 1 ms 204 KB Correct answer: answer = 1
22 Correct 1 ms 204 KB Correct answer: answer = 1
23 Correct 83 ms 716 KB Correct answer: answer = 2040
24 Correct 1 ms 204 KB Correct answer: answer = 2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Incorrect 1 ms 204 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Incorrect 1 ms 204 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Incorrect 1 ms 204 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Incorrect 1 ms 204 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -