이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 <int> rem;
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);
}
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));
memset(lf, 0x3f3f3f3f, sizeof(lf));
memset(rg, -0x3f3f3f3f, sizeof(rg));
for (int i = 0; i < m; i++)
{
rem.push_back(r[i]);
lf[r[i]] = min(lf[r[i]], c[i]);
rg[r[i]] = max(rg[r[i]], c[i]);
}
sort(rem.begin(), rem.end());
rem.erase(unique(rem.begin(), rem.end()), rem.end());
sort(rem.begin(), rem.end());
// cout << rem.size() << '\n';
// for (int i = 0; i < rem.size(); i++)
// cout << lf[rem[i]] << ' ' << rg[rem[i]] << '\n';
dp[0][1] = area(min(lf[rem[0]], rem[0]), max(rem[0], rg[rem[0]]));
cur[0][1] = {min(lf[rem[0]], rem[0]), max(rem[0], rg[rem[0]])};
for (int i = 1; i < rem.size(); i++)
{
for (int t = 0; t < i; t++)
{
for (int j = 1; j <= k; j++)
{
if (dp[t][j - 1] + area(min(lf[rem[i]], rem[i]), max(rem[i], rg[rem[i]])) < dp[i][j])
{
dp[i][j] = dp[t][j - 1] + area( min(lf[rem[i]], rem[i]), max(rem[i], rg[rem[i]]) ) ;
cur[i][j] = {min(lf[rem[i]], rem[i]), max(rg[rem[i]], rem[i])};
}
auto [ll, rr] = cur[t][j];
int new_area = max(sqr(rem[i] - rem[t] + 1), area(min({rem[t], ll, lf[rem[i]]}), max({rr, rg[rem[i]], rem[i]})));
int old_area = sqr(rr - ll + 1);
if (dp[t][j] - old_area + new_area < dp[i][j])
{
dp[i][j] = dp[t][j] - old_area + new_area;
cur[i][j] = {min({rem[t], ll, lf[rem[i]]}), max({rr, rg[rem[i]], rem[i]})};
}
}
}
}
int ans = 0x3f3f3f3f;
for (int j = 1; j <= k; j++)
ans = min(ans, dp[rem.size() - 1][j]);
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});
// }
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 1; i < rem.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... |