This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
using namespace std;
#define v vector
#define pii pair<int,int>
#define fi first
#define se second
int N,K;
v<int> pos;
v<v<v<long long>>> memo;
long long diagSolve(int l, int r, int k){
long long curArea=(pos[r]-pos[l]+1) * (pos[r]-pos[l]+1);
if(r==N-1){
return memo[l][r][k] = curArea;
}
if(k==K-1){
return memo[l][r][k] = (pos.back()-pos[l]+1) * (pos.back()-pos[l]+1);
}
if(memo[l][r][k]!=-1) return memo[l][r][k];
long long takePhoto = curArea+diagSolve(r+1,r+1,k+1);
long long dont = diagSolve(l,r+1,k);
return memo[l][r][k] = min(takePhoto, dont);
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
bool subTwo=true;
for(int i=0;i<n;i++){
if(r[i]!=c[i]) subTwo=false;
}
if(k==n && m<=100){//sub 1
v<v<bool>> squares(m,v<bool>(m,false));
for(int i=0;i<n;i++){
int low=min(r[i],c[i]);
int high=max(r[i],c[i]);
for(int a=low;a<=high;a++){
for(int b=low;b<=high;b++){
squares[a][b]=true;
}
}
}
long long out=0;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
out+=squares[i][j];
}
}
return out;
}
else if(subTwo){//assume sub 2
//as all along diagonal can do dp with n^3
K=k;
N=n;
set<int> tmp;
for(int i:r) tmp.insert(i);
for(int i:tmp) pos.push_back(i);
N=pos.size();
memo=v<v<v<long long>>>(pos.size()+1,v<v<long long>>(pos.size()+1,v<long long>(k+1,-1)));
return diagSolve(0,0,0);
}
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:70:1: warning: control reaches end of non-void function [-Wreturn-type]
70 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |