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 file if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); }
// #define int long long
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
if (s.size()) setIn(s+".in"), setOut(s+".out");
}
const int maxn = 1002, sz = 502;
vector <pair <int, int>> rem, tmp;
int lf[maxn], rg[maxn], dp[maxn][sz];
pair <int, int> cur[maxn][sz];
int sqr(int p)
{
return p * p;
}
int area(int l, int r)
{
return sqr(r - l + 1);
}
bool cMp (const pair <int, int> &a, const pair <int, int> &b)
{
if (a.first == b.first)
return a.second > b.second;
else
return a.first < b.first;
}
long long take_photos(int n, int m, int k, vector <int> R, vector <int> c)
{
//square n x n
//picture <= m
swap(n, m);
memset(dp, 0x3f3f3f3f, sizeof(dp));
for (int i = 0; i < m; i++)
{
tmp.push_back({min(R[i], c[i]), max(R[i], c[i])});
}
sort(tmp.begin(), tmp.end(), cMp);
rem.push_back(tmp[0]);
// cout << tmp[0].first << ' ' << tmp[0].second << '\n';
for (int i = 1; i < tmp.size(); i++)
{
if (tmp[i].first >= rem.back().first && tmp[i].second <= rem.back().second)
continue;
rem.push_back(tmp[i]);
// cout << tmp[i].first << ' ' << tmp[i].second << '\n';
}
// dp[0][0] = 0;
dp[0][1] = area(rem[0].first, rem[0].second);
for (int i = 1; i < rem.size(); i++)
{
for (int t = 0; t < i; t++)
{
auto [l, r] = rem[i];
auto [ll, rr] = rem[t];
for (int j = 1; j <= k; j++)
{
dp[i][j] = min({dp[i][j], dp[t][j] + area(ll, max(rr, r)) - (t != 0) ? (sqr(max(rem[t - 1].second - rem[t].first + 1, 0))) : 0, dp[t][j - 1] + sqr(r - l + 1)});
}
}
}
int ans = 0x3f3f3f3f;
for (int j = 1; j <= k; j++)
ans = min(ans, dp[rem.size() - 1][j]);
// for (int i = 1; i < rem.size(); i++)
// for (int j = 1; j <= k; j++)
// cout << dp[i][j] << " \n"[j == k];
// cout << ans;
return ans;
}
// signed main()
// {
// // setIO();
// file;
// ios::sync_with_stdio(0); cin.tie(0);
// // take_photos(2, 6, 2, {1, 4}, {4, 1});
// // take_photos(5, 7, 2, {0, 4, 4, 4, 4}, {3, 4, 6, 5, 6});
// }
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 1; i < tmp.size(); i++)
| ~~^~~~~~~~~~~~
aliens.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 1; i < rem.size(); i++)
| ~~^~~~~~~~~~~~
aliens.cpp: In function 'void setIn(std::string)':
aliens.cpp:8:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | void setIn(string s) { freopen(s.c_str(),"r",stdin); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
aliens.cpp: In function 'void setOut(std::string)':
aliens.cpp:9:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | void setOut(string s) { freopen(s.c_str(),"w",stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |