結果
| 問題 | No.3437 [Cherry 8th Tune C] Silhouette |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-01-25 17:45:18 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 351 ms / 2,000 ms |
| コード長 | 4,138 bytes |
| 記録 | |
| コンパイル時間 | 593 ms |
| コンパイル使用メモリ | 71,512 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-25 17:45:25 |
| 合計ジャッジ時間 | 6,731 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 3437.cc: No.3437 [Cherry 8th Tune C] Silhouette - yukicoder
*/
#include<cstdio>
#include<algorithm>
#include<numeric>
#include<tuple>
using namespace std;
/* constant */
const int MOD = 998244353;
/* typedef */
using ll = long long;
using tp3 = tuple<ll,ll,ll>;
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }
explicit operator int() const { return v; }
MI operator+(const MI m) const { return MI(v + m.v); }
MI operator-(const MI m) const { return MI(v + MOD - m.v); }
MI operator-() const { return MI(MOD - v); }
MI operator*(const MI m) const { return MI((long long)v * m.v); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
bool operator==(const MI m) const { return v == m.v; }
bool operator!=(const MI m) const { return v != m.v; }
MI pow(int n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
using mi = MI<MOD>;
template <typename T>
struct Pt {
T x, y;
Pt() {}
Pt(T _x, T _y) : x(_x), y(_y) {}
Pt(const Pt<T> &p) : x(p.x), y(p.y) {}
Pt<T> operator+(const Pt<T> p) const { return Pt<T>(x + p.x, y + p.y); }
Pt<T> operator-() const { return Pt<T>(-x, -y); }
Pt<T> operator-(const Pt<T> p) const { return Pt<T>(x - p.x, y - p.y); }
Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
T dot(Pt<T> v) const { return x * v.x + y * v.y; }
T cross(Pt<T> v) const { return x * v.y - y * v.x; }
T d2() { return x * x + y * y; }
bool operator==(const Pt<T> pt) const { return x == pt.x && y == pt.y; }
};
using ptd = Pt<double>;
using ptmi = Pt<mi>;
struct Rat {
ll n, d;
Rat(): n(), d(1) {}
Rat(ll _n): n(_n), d(1) {}
Rat(ll _n, ll _d): n(_n), d(_d) { reduce(); }
void reduce() {
if (d == 0) n = 0;
else {
if (d < 0) n = -n, d = -d;
ll g = gcd(abs(n), d);
n /= g, d /= g;
}
}
explicit operator double() const { return (double)n / d; }
explicit operator mi() const { return mi(n) * mi(d).inv(); }
Rat operator+(const Rat r) {
return Rat(n * r.d + r.n * d, d * r.d);
}
Rat operator-(const Rat r) {
return Rat(n * r.d - r.n * d, d * r.d);
}
Rat operator*(const Rat r) {
return Rat(n * r.n, d * r.d);
}
Rat operator/(const Rat r) {
return Rat(n * r.d, d * r.n);
}
void print() const { printf("%lld/%lld ", n, d); }
};
using ptr = Pt<Rat>;
/* global variables */
mi inv2 = mi(2).inv();
/* subroutines */
tp3 readtp3() {
ll x, y, z;
scanf("%lld%lld%lld", &x, &y, &z);
return {x, y, z};
}
ptr project(tp3 p, tp3 l) {
auto [px, py, pz] = p;
auto [lx, ly, lz] = l;
ll vx = px - lx, vy = py - ly, vz = pz - lz;
Rat rx = Rat(vx * lz, -vz);
Rat ry = Rat(vy * lz, -vz);
return ptr(rx, ry);
}
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
tp3 a = readtp3(), b = readtp3(), c = readtp3();
tp3 l = readtp3();
auto ra = project(a, l);
auto rb = project(b, l);
auto rc = project(c, l);
//ra.x.print(); ra.y.print(); putchar('\n');
//rb.x.print(); rb.y.print(); putchar('\n');
//rc.x.print(); rc.y.print(); putchar('\n');
auto da = ptd((double)ra.x, (double)ra.y);
auto db = ptd((double)rb.x, (double)rb.y);
auto dc = ptd((double)rc.x, (double)rc.y);
auto ma = ptmi(mi(ra.x), mi(ra.y));
auto mb = ptmi(mi(rb.x), mi(rb.y));
auto mc = ptmi(mi(rc.x), mi(rc.y));
mi s = 0;
if ((db - da).cross(dc - da) >= 0.0) {
s = (mb - ma).cross(mc - ma);
}
else {
s = (mc - ma).cross(mb - ma);
}
s *= inv2;
printf("%d\n", (int)s);
}
return 0;
}
tnakao0123