Submission #1051239

#TimeUsernameProblemLanguageResultExecution timeMemory
1051239ReLiceAliens (IOI16_aliens)C++14
0 / 100
24 ms63076 KiB
#include "aliens.h" #include <bits/stdc++.h> #define ll int #define sz size(); #define all(x) x.begin(),x.end() #define vll vector<ll> #define str string #define pb push_back #define bc back() using namespace std; const ll N=4e3+5; ll sq(ll x){ return x*x; } ll dp[N][N]; long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) { ll i,j,q; vll len,nxt; {//deleting unnecessary ones vll mx(m, m),nr; for(i=0;i<n;i++){ if(r[i] < c[i]) swap(r[i], c[i]); mx[r[i]] = min(mx[r[i]], c[i]); } for(i=m-1;i>=0;i--){ if(mx[i] >= i)continue; if(nr.empty() || mx[nr.bc] > mx[i]){ //~ cout<<i<<endl; //~ cout<<mx[i]<<endl<<endl; nr.pb(i); len.pb(i-mx[i]+1); } } nr.pb(-1), len.pb(-1);//changing indexation reverse(all(nr)); reverse(all(len)); r=nr; n=r.size()-1; } c.clear(); c.pb(0); for(i=1;i<=n;i++){ nxt.pb(r[i]-len[i]+1); c.pb(nxt.bc); } memset(dp, 0x3f,sizeof(dp)); dp[0][0]=0; for(i=1;i<=n;i++){ for(j=1;j<=k;j++){ for(q=0;q<i;q++){ if(dp[q][j-1] >= dp[0][1])continue; dp[i][j] = min(dp[i][j], dp[q][j-1] + sq(r[i] - nxt[q] + 1) - sq(r[q] - nxt[q] + 1)); } } } ll ans=dp[0][1]; for(i=0;i<=k;i++)ans = min(ans, dp[n][i]); return dp[n][k]; }
#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...