Submission #1131387

#TimeUsernameProblemLanguageResultExecution timeMemory
1131387LuvidiAliens (IOI16_aliens)C++20
12 / 100
92 ms2400 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { vector<pair<int,int>> tm,st; for(int i=0;i<n;i++){ if(r[i]>c[i])swap(r[i],c[i]); tm.push_back({r[i],c[i]}); } sort(tm.begin(),tm.end(),[](pair<int,int> p1,pair<int,int> p2){ if(p1.first!=p2.first)return p1.first<p2.first; return p1.second>p2.second; }); st.push_back({-1,-1}); for(auto p:tm){ if(p.second>st.back().second)st.push_back(p); } n=st.size()-1; long long dp[n+1][k+1],a[n+1],h[n+1]; for(int i=0;i<=n;i++){ a[i]=st[i].second+1; h[i]=st[i].second-st[i].first+1; } for(int i=1;i<=n;i++)dp[i][0]=1e18; for(int i=0;i<=k;i++)dp[0][i]=0; for(int j=1;j<=k;j++){ for(int i=1;i<=n;i++){ dp[i][j]=1e18; for(int p=i-1;p>-1;p--){ long long x=a[i]-a[p+1]+h[p+1]; dp[i][j]=min(dp[i][j],x*x+dp[p][j-1]); } } } return dp[n][k]; }

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...