Submission #755522

# Submission time Handle Problem Language Result Execution time Memory
755522 2023-06-10T08:16:08 Z alexander707070 Aliens (IOI16_aliens) C++14
0 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

const long long inf=1e16;

struct seg{
    long long l,r;

    inline friend bool operator < (seg fr,seg sc){
        if(fr.l!=sc.l)return fr.l<sc.l;
        return fr.r>sc.r;
    }
};

int n,m,k;
seg a[50007];
vector<seg> v;

long long dp[50007][4007];

long long cost(int l,int r){
    if(l==1)return (v[r].r-v[l].l+1)*(v[r].r-v[l].l+1); 
    return (v[r].r-v[l].l+1)*(v[r].r-v[l].l+1)-max( (v[l-1].r-v[l].l+1)*(v[l-1].r-v[l].l+1) , 0LL);
}

void solve(int k){
    for(int i=1;i<v.size();i++){
        dp[i][k]=inf;
        for(int f=i;f>=1;f--){
            dp[i][k]=min(dp[i][k],dp[f-1][k-1]+cost(f,i));
        }
    }
}

long long take_photos(int N, int M, int K, vector<int> r, vector<int> c){
    n=N; m=M; k=K;

    for(int i=0;i<n;i++){
        a[i+1]={min(r[i],c[i]),max(r[i],c[i])};
    }
    sort(a+1,a+n+1);

    v.push_back({-1,-1});
    for(int i=1;i<=n;i++){
        while(!v.empty() and v.back().l>=a[i].l and v.back().r<=a[i].r)v.pop_back();
        v.push_back(a[i]);
    }

    dp[0][0]=0;
    for(int i=1;i<v.size();i++)dp[i][0]=inf;
    
    for(int i=1;i<=k;i++){
        solve(i);
    }

    return dp[v.size()-1][k];
}

/*
int main(){

    cout<<take_photos(5, 7, 2, {0, 4, 4, 4, 4}, {3, 4, 6, 5, 6})<<"\n";

}
*/

Compilation message

aliens.cpp: In function 'void solve(int)':
aliens.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<seg>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=1;i<v.size();i++){
      |                 ~^~~~~~~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<seg>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=1;i<v.size();i++)dp[i][0]=inf;
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Correct answer: answer = 4
2 Incorrect 1 ms 212 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Correct answer: answer = 1
2 Correct 0 ms 212 KB Correct answer: answer = 4
3 Correct 2 ms 212 KB Correct answer: answer = 1
4 Correct 2 ms 212 KB Correct answer: answer = 5
5 Incorrect 1 ms 340 KB Wrong answer: output = 21, expected = 41
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Correct answer: answer = 4
2 Incorrect 1 ms 212 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Correct answer: answer = 4
2 Incorrect 1 ms 212 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Correct answer: answer = 4
2 Incorrect 1 ms 212 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Correct answer: answer = 4
2 Incorrect 1 ms 212 KB Wrong answer: output = 1, expected = 4
3 Halted 0 ms 0 KB -