제출 #1175775

#제출 시각아이디문제언어결과실행 시간메모리
1175775totoroAliens (IOI16_aliens)C++17
4 / 100
1 ms328 KiB
// SOLVED SUBTASK 1 (04 pts) // SOLVED SUBTASK 2 (12 pts) // SOLVED SUBTASK 3 (09 pts) // SOLVED SUBTASK 4 (16 pts) // SOLVED SUBTASK 5 (19 pts) // UNSOLVED SUBTASK 6 (40 pts) // [+-+]---------------------- // TOTAL 60/100 pts #include "aliens.h" #include <algorithm> #include <climits> #include <cmath> #include <iostream> #include <vector> struct Coordinate { long long row, col; Coordinate(long long row, long long col) : row(std::min(row, col)), col(std::max(row, col)) {} bool operator<(const Coordinate& other) const { if (row == other.row) { return col > other.col; } return row < other.row; } }; struct Range { long long start, end; Range(long long start, long long end) : start(start), end(end) {}; long long merge(const Range& other) const { return 2 * (other.start - start) * (other.end - end) - (other.start > end ? (other.start - end - 1) * (other.start - end - 1) : 0); } }; struct Parabola { double h, v; double evaluate(double x) { return (x - h) * (x - h) + v; } }; double intersect(Parabola a, Parabola b) { return (b.h * b.h + b.v - a.h * a.h - a.v) / (2.0 * (b.h - a.h)); } struct ConvexHull { std::vector<Parabola> parabolas; std::vector<double> left, right; std::vector<int> indexes; int counter = 0; void insert(Parabola p) { while (!parabolas.empty() && intersect(p, parabolas.back()) <= left.back()) { parabolas.pop_back(); left.pop_back(); right.pop_back(); indexes.pop_back(); } if (parabolas.empty()) { parabolas.push_back(p); left.push_back(-1e18); // neg infty right.push_back(1e18); // infty indexes.push_back(counter); } else { double x = intersect(p, parabolas.back()); right.back() = x; parabolas.push_back(p); left.push_back(x); right.push_back(1e18); // infty indexes.push_back(counter); } ++counter; // std::cout << "inserted (x-" << p.h << ")^2 + " << p.v << '\n'; } std::pair<int, double> min(double x) { int index = std::lower_bound(left.begin(), left.end(), x) - left.begin() - 1; return {indexes[index], parabolas[index].evaluate(x)}; } }; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { std::vector<Coordinate> points; for (size_t i = 0; i < n; ++i) { points.push_back(Coordinate(r[i], c[i])); } std::sort(points.begin(), points.end()); std::vector<Range> ranges; long long furthestStart = -1; long long furthestEnd = -1; for (size_t i = 0; i < points.size(); ++i) { Coordinate point = points[i]; if (point.row > furthestStart && point.col > furthestEnd) { ranges.emplace_back(point.row, point.col); furthestStart = point.row; furthestEnd = point.col; } } ranges.push_back({(long long)1e15, (long long)1e15}); long long lo = -1e10, hi = 1e10; long long anss = 0, cntt = 0; while (lo < hi) { long long penalty = std::floor((lo + hi) / 2.0); ConvexHull hull; std::vector<long long> ans; std::vector<long long> cnt; hull.insert(Parabola{(double)ranges[0].start, 0.0}); ans.push_back(0), cnt.push_back(0); for (size_t range = 0; range < ranges.size() - 1; ++range) { // if (range == 0) { // ans.push_back((ranges[range].end - ranges[0].start + 1) * (ranges[range].end - ranges[0].start + 1) + penalty); // cnt.push_back(1); // hull.insert(Parabola{(double)ranges[range + 1].start, (ranges[range].end - ranges[0].start + 1) * (ranges[range].end - ranges[0].start + 1) - std::pow(std::max(0ll, ranges[range].end - ranges[range + 1].start + 1), 2) + penalty}); // continue; // } auto [from, best] = hull.min(ranges[range].end + 1); hull.insert(Parabola{(double)ranges[range + 1].start, (double)best - std::pow(std::max(0ll, ranges[range].end - ranges[range + 1].start + 1), 2) + penalty}); cnt.push_back(cnt[from] + 1); ans.push_back(best + penalty); } if (cnt.back() > k) { lo = penalty + 1; } else { hi = penalty; anss = ans.back(); cntt = cnt.back(); } } // std::cout << cntt << '\n'; // std::cout << lo << '\n'; return anss - cntt * lo; }

컴파일 시 표준 에러 (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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...