#include "aliens.h"
#include <iostream>
#include <algorithm>
#include <utility>
#include <climits>
#include <set>
using namespace std;
long long sq(long long a) {
return a * a;
}
long long sq(int a) {
return (long long)(a) * a;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
set<pair<int, int>> curPoints;
for (int i = 0; i < n; ++i) curPoints.emplace(min(r[i], c[i]), max(r[i], c[i]));
long long bestVal = LLONG_MAX / 2;
while (true) {
bestVal = LLONG_MAX / 2;
auto curStart = curPoints.end(), curEnd = curPoints.end();
for (auto i = curPoints.begin(); i != curPoints.end(); ++i) {
for (auto j = next(i); j != curPoints.end(); ++j) {
auto a = *i, b = *j;
pair<int, int> newRange = make_pair(min(a.first, b.first), max(a.second, b.second)), overlap = make_pair(max(a.first, b.first), min(a.second, b.second));
long long newDist = sq(newRange.second - newRange.first + 1) - sq(a.second - a.first + 1) - sq(b.second - b.first + 1) + sq(max(0, overlap.second - overlap.first + 1));
if (newDist < bestVal) {
bestVal = newDist;
curStart = i;
curEnd = j;
}
}
}
if (curPoints.size() > k) {
auto a = *curStart, b = *curEnd;
pair<int, int> newRange = make_pair(min(a.first, b.first), max(a.second, b.second));
curPoints.erase(curStart);
curPoints.erase(curEnd);
curPoints.insert(newRange);
} else break;
}
long long res = 0;
pair<int, int> prev = make_pair(-1, -1), cur = make_pair(-1, -1);
for (auto i = curPoints.begin(); i != curPoints.end(); ++i) {
auto a = *i;
if (a.first != cur.first) {
res += sq(cur.second - cur.first + 1) - sq(max(min(cur.second, prev.second) - max(cur.first, prev.first) + 1, 0));
prev = cur;
cur = a;
} else cur.second = max(cur.second, a.second);
}
res += sq(cur.second - cur.first + 1) - sq(max(min(cur.second, prev.second) - max(cur.first, prev.first) + 1, 0));
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |