Submission #1257343

#TimeUsernameProblemLanguageResultExecution timeMemory
1257343MingyuanzAliens (IOI16_aliens)C++20
25 / 100
95 ms2400 KiB
#include "aliens.h"
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<Int,Int>
#define f first
#define s second
#define INF (int)1e17
#define MOD (int)(1e9+7)
#define MAXN 100005
#define enl '\n'
#define DB(CODE) cout<<'\t'<<CODE<<'\n';
#define SP <<' '<<
#define Int long long
typedef long long ll;
using namespace std;
Int power2(Int x){
    return x*x;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
    vector<pii> inp(n),arr={{-1,-1}};
    for(Int i=0; i<n; i++) inp[i]={min(r[i],c[i]),max(r[i],c[i])};
    sort(inp.begin(),inp.end(),[](pii a,pii b){return a.f<b.f || (a.f==b.f && a.s>b.s);});
    for(auto p: inp){
        if(p.s<=arr.back().s) continue;
        arr.pb(p);
    }
    n=arr.size()-1;
    Int dp[k+1][n+1];
    for(Int i=0; i<=k; i++) for(Int j=0; j<=n; j++) dp[i][j]=INF;
    dp[0][0]=0;
    for(Int i=1; i<=n; i++) for(Int c=1; c<=k; c++){
        for(Int j=i; j>0; j--) dp[c][i]=min(dp[c][i],dp[c-1][j-1]+power2(arr[i].s-arr[j].f+1)-power2(max(arr[j-1].s-arr[j].f+1,0ll)));
    }
    Int ans=INF;
    for(Int i=0; i<=k; i++) ans=min(ans,dp[i][n]);
    return ans;
}

Compilation message (stderr)

aliens.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...