QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91768 | #4515. Triangles | KHIN | 0 | 2463ms | 3788kb | C++17 | 5.8kb | 2023-03-29 15:51:16 | 2023-03-29 15:51:19 |
Judging History
answer
# include <cstdlib>
# include <tuple>
# include <type_traits>
# include <utility>
# include <cassert>
# include <vector>
# include <algorithm>
# include <numeric>
# include <iostream>
# include <istream>
# include <ostream>
namespace khin {
using namespace std;
namespace main {
inline namespace source {
template <typename T, enable_if_t<is_signed<T>::value, int> = 0>
constexpr int sgn(T const value) { return (value > 0) - (value < 0); }
}
namespace a { void main(); }
namespace b { void main(); }
namespace c { void main(); }
namespace d { void main(); }
namespace e { void main(); }
}
}
int main() { khin::main::e::main(); }
namespace khin::main::e {
namespace test_case {
constexpr uint n_max(3'000);
struct vector {
int x, y;
constexpr vector() : x(), y() {}
explicit constexpr vector(int const x, int const y) : x(x), y(y) {}
constexpr vector operator+() const { return vector(+x, +y); }
constexpr vector operator-() const { return vector(-x, -y); }
constexpr friend vector operator+(vector const u, vector const v)
{ return vector(u.x + v.x, u.y + v.y); }
constexpr friend vector operator-(vector const u, vector const v)
{ return vector(u.x - v.x, u.y - v.y); }
constexpr friend long operator*(vector const u, vector const v)
{ return 1l * u.x * v.y - 1l * u.y * v.x; }
} typedef point;
constexpr bool comp(vector const u, vector const v) {
ushort const tu(u.x < 0 ? 0 : u.x == 0 ? u.y < 0 ? 1 : 3 : 2);
ushort const tv(v.x < 0 ? 0 : v.x == 0 ? v.y < 0 ? 1 : 3 : 2);
uint const lu(abs(u.x) + abs(u.y)), lv(abs(v.x) + abs(v.y));
return tu == tv ? u * v ? u * v > 0 : lu < lv : tu < tv;
}
uint n; point p[n_max + 1]; std::vector<uint> s, t;
std::vector<tuple<uint, uint, uint>> ans;
inline void printerr(uint const a, uint const b, uint const c) {
fprintf(stderr, "(%u, %u) ", p[a].x, p[a].y);
fprintf(stderr, "(%u, %u) ", p[b].x, p[b].y);
fprintf(stderr, "(%u, %u)\n", p[c].x, p[c].y);
}
void main(ushort const x) {
cin >> n;
for (uint i(1); i <= n; ++i) cin >> p[i].x >> p[i].y;
s.resize(n), iota(s.begin(), s.end(), 1u);
while (s.size() >= 3) {
auto const cmp0 = [&] (uint const i, uint const j)
{ return make_pair(p[i].x, p[i].y) < make_pair(p[j].x, p[j].y); };
uint const a(*min_element(s.begin(), s.end(), cmp0));
s.erase(min_element(s.begin(), s.end(), cmp0));
auto const cmp1 = [&] (uint const i, uint const j) {
vector const u(p[i] - p[a]), v(p[j] - p[a]);
ushort const tu(u.x < 0 ? 0 : u.x == 0 ? u.y < 0 ? 1 : 3 : 2);
ushort const tv(v.x < 0 ? 0 : v.x == 0 ? v.y < 0 ? 1 : 3 : 2);
uint const lu(abs(u.x) + abs(u.y)), lv(abs(v.x) + abs(v.y));
return tu == tv ? u * v ? u * v > 0 : lu < lv : tu < tv;
};
uint const b(*min_element(s.begin(), s.end(), cmp1));
s.erase(min_element(s.begin(), s.end(), cmp1));
auto const cmp2 = [&] (uint const i, uint const j) {
vector const u(p[b] - p[i]), v(p[b] - p[j]);
ushort const tu(u.x < 0 ? 0 : u.x == 0 ? u.y < 0 ? 1 : 3 : 2);
ushort const tv(v.x < 0 ? 0 : v.x == 0 ? v.y < 0 ? 1 : 3 : 2);
uint const lu(abs(u.x) + abs(u.y)), lv(abs(v.x) + abs(v.y));
return tu == tv ? u * v ? u * v < 0 : lu < lv : tu > tv;
};
uint const c(*min_element(s.begin(), s.end(), cmp2));
s.erase(min_element(s.begin(), s.end(), cmp2));
if (!((p[a] - p[b]) * (p[b] - p[c])))
{ s.push_back(a), s.push_back(b), s.push_back(c); break; }
/* fputs("ins ", stderr), printerr(a, b, c); */
ans.emplace_back(a, b, c);
}
if (s.size() > 1) {
while (!ans.empty() && 2 * t.size() < s.size()) {
auto const [a, b, c](ans.back()); ans.pop_back();
/* fputs("era ", stderr), printerr(a, b, c); */
((p[a] - p[s[0]]) * (p[a] - p[s[1]]) ? t : s).push_back(a);
((p[b] - p[s[0]]) * (p[b] - p[s[1]]) ? t : s).push_back(b);
((p[c] - p[s[0]]) * (p[c] - p[s[1]]) ? t : s).push_back(c);
}
auto const cmp0 = [] (uint const i, uint const j)
{ return make_pair(p[i].x, p[i].y) < make_pair(p[j].x, p[j].y); };
sort(s.begin(), s.end(), cmp0);
vector const vs(p[s[1]] - p[s[0]]);
auto const find = [&] {
uint const b(s.back());
auto const comp = [&] (uint const i, uint const j) {
vector vi(p[i] - p[b]); assert(vi * vs);
vector vj(p[j] - p[b]); assert(vj * vs);
if (sgn(vi * vs) != sgn(vj * vs))
return sgn(vi * vs) > sgn(vj * vs);
return vi * vj * sgn(vi * vs) < 0;
};
auto const it(min_element(t.begin(), t.end(), comp));
uint const tmp(*it); t.erase(it); return tmp;
};
auto const find1 = [&] {
uint const a(s.back()); s.pop_back();
uint const b(find());
uint const c(s.back()); s.pop_back();
/* fputs("ins ", stderr), printerr(a, b, c); */
ans.emplace_back(a, b, c);
};
auto const find2 = [&] {
uint const a(find()), b(find());
uint const c(s.back()); s.pop_back();
/* fputs("ins ", stderr), printerr(a, b, c); */
ans.emplace_back(a, b, c);
};
while (s.size() + t.size() >= 3 && !t.empty())
(s.size() < t.size() ? find2() : find1());
}
printf("Case #%hu: %zu\n", x, ans.size());
for (auto const [p, q, r] : ans) printf("%u %u %u\n", p, q, r);
s.clear(), t.clear(), ans.clear();
}
}
void main() {
ushort t; cin >> t;
for (ushort i(1); i <= t; ++i) test_case::main(i);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 3604kb
input:
100 10 220238472 224691753 770968360 1070897 222060078 225731229 213423928 -699125511 571809960 -531790999 -29325160 82281481 523892900 397968241 134123366 175551277 -48116654 71558357 79192162 144205493 6 -800120306 681957950 -800120120 681958048 -800120239 681957972 -800120068 681958102 -800120280...
output:
Case #1: 3 9 4 6 10 5 8 1 2 3 Case #2: 2 1 3 5 6 2 4 Case #3: 4 11 12 7 4 3 8 10 5 1 9 2 6 Case #4: 0 Case #5: 2 2 3 1 5 4 6 Case #6: 3 1 4 7 5 6 8 2 3 9 Case #7: 2 7 6 4 3 1 2 Case #8: 3 2 7 1 10 9 6 3 8 4 Case #9: 4 11 3 9 4 5 2 12 6 10 8 1 7 Case #10: 2 5 2 3 1 6 4 Case #11: 4 11 5 8 9 12 10 3 2 ...
result:
wrong answer intersection detected! [2] (test case 3)
Test #2:
score: 0
Wrong Answer
time: 2463ms
memory: 3788kb
input:
100 3000 -92089322 -224238223 -92147554 -225776486 -91601000 -225100640 -92024176 -225644144 -90703509 -224917680 -89202055 -225283952 -92681755 -224149407 -92347180 -225441739 -92259568 -225588653 -91979455 -224254694 -92673281 -224244242 -92527577 -224172521 -90804449 -224883170 -92641474 -2249482...
output:
Case #1: 1000 2743 1593 436 169 1759 2938 2812 2792 2457 46 624 2409 2863 424 999 1335 2697 238 311 2919 1095 1332 1523 787 1515 1042 534 1830 2114 1336 2496 916 275 2666 2023 1297 1693 2755 2234 2685 533 589 1087 2993 1182 2173 2386 2184 1185 2878 1958 2232 764 2584 235 1570 2911 747 2850 1713 57 2...
result:
wrong answer intersection detected! [2] (test case 9)