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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//-------------------
const int mxn=500+5;
ll dp[mxn][mxn],arr[mxn],x[mxn],y[mxn],color[mxn][mxn];
ll solve(int n,int m){
for(int ind=1;ind<=n;ind++){
for(int i=min(x[ind],y[ind]);i<=max(x[ind],y[ind]);i++){
for(int j=min(x[ind],y[ind]);j<=max(x[ind],y[ind]);j++){
color[i][j]=1;
}
}
}
int ans=0;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(color[i][j]){
ans++;
}
}
}
return ans;
}
long long take_photos(int n, int m, int k, vector<int> vt,vector<int> c) {
for(int i=0;i<vt.size();i++){
arr[i+1]=vt[i];
x[i+1]=vt[i];
y[i+1]=c[i];
}
if(n<=50&&m<=100&&k==n){
return solve(n,m);
}
sort(arr+1,arr+n+1);
for(int i=1;i<=n;i++){
dp[1][i]=(arr[i]-arr[1]+1)*(arr[i]-arr[1]+1);
}
for(int i=2;i<=k;i++){
for(int j=1;j<=n;j++){
dp[i][j]=dp[i-1][j];
for(int k=1;k<=j;k++){
dp[i][j]=min(dp[i][j],dp[i-1][k-1]+(arr[j]-arr[k]+1)*(arr[j]-arr[k]+1));
}
}
}
return dp[k][n];
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<vt.size();i++){
| ~^~~~~~~~~~
# | 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... |