QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#349013 | #5067. Two Walls | ideograph_advantage | WA | 1ms | 3612kb | C++20 | 6.5kb | 2024-03-09 23:02:03 | 2024-03-09 23:02:04 |
Judging History
answer
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ...U> void debug(T a, U ...b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll __int128
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
#define iter(a) a.begin(), a.end()
using Pt = pair<ll, ll>;
using Line = pair<Pt, Pt>;
#define X first
#define Y second
Pt operator+(Pt a, Pt b){ return {a.X + b.X, a.Y + b.Y}; }
Pt operator-(Pt a, Pt b){ return {a.X - b.X, a.Y - b.Y}; }
Pt operator*(ll i, Pt v){ return {i * v.X, i * v.Y}; }
Pt operator*(Pt v, ll i){ return {i * v.X, i * v.Y}; }
Pt operator/(Pt v, ll i){ return {v.X / i, v.Y / i}; }
ll dot(Pt a, Pt b){ return a.X * b.X + a.Y * b.Y; }
ll cross(Pt a, Pt b){ return a.X * b.Y - a.Y * b.X; }
ll abs2(Pt v){ return v.X * v.X + v.Y * v.Y; }
int sgn(ll v){ return v > 0 ? 1 : (v < 0 ? -1 : 0); }
int ori(Pt a, Pt b, Pt c){ return sgn(cross(b - a, c - a)); }
bool collinearity(Pt a, Pt b, Pt c){ return ori(a, b, c) == 0; }
bool btw(Pt p, Pt a, Pt b){ return collinearity(p, a, b) && sgn(dot(a - p, b - p)) <= 0; }
istream& operator>>(istream& i, __int128& v){
long long t;
i >> t;
v = t;
return i;
}
ostream& operator<<(ostream& o, __int128& v){
long long t;
t = v;
o << t;
return o;
}
template<class A, class B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.ff << ", " << p.ss << ")";
}
bool intersect(Line a, Line b){
Pt p1, p2, p3, p4;
tie(p1, p2) = a;
tie(p3, p4) = b;
if(btw(p1, p3, p4) || btw(p2, p3, p4) || btw(p3, p1, p2) || btw(p4, p1, p2)) return true;
return ori(p1, p2, p3) * ori(p1, p2, p4) < 0 && ori(p3, p4, p1) * ori(p3, p4, p2) < 0;
}
bool intersect2(Line a, Line b){
Pt p1, p2, p3, p4;
tie(p1, p2) = a;
tie(p3, p4) = b;
return ori(p1, p2, p3) * ori(p1, p2, p4) < 0 && ori(p3, p4, p1) * ori(p3, p4, p2) < 0;
}
bool inside(Pt p, Pt a, Pt b, Pt c){
return ori(a, p, b) * ori(a, p, c) <= 0 &&
ori(b, p, a) * ori(b, p, c) <= 0 &&
ori(c, p, a) * ori(c, p, b) <= 0;
}
bool inside2(Pt p, Pt a, Pt b, Pt c){
return ori(a, p, b) * ori(a, p, c) < 0 &&
ori(b, p, a) * ori(b, p, c) < 0 &&
ori(c, p, a) * ori(c, p, b) < 0;
}
bool ray_intersect(Pt A, Pt Va, Pt B, Pt Vb){
if(-ori (A, B, A + Va) != ori(B, A, B + Vb)) return 0;
if(ori(A, B, A + Va) == 0) return 1 - btw(A, B, A + Va) && btw(B, A, B + Vb);
return ori(A, A - Vb, B) == ori(A, A - Vb, A + Va);
}
void get_case(int t){
long long a[12];
for(int i = 0; i < t; i++){
for(int j = 0; j < 12; j++) cin >> a[j];
}
for(int i = 0; i < 12; i++){
cout << a[i] << ' ';
}
cout << '\n';
}
int tNum = 0;
void solve(){
tNum++;
Pt A, B, C, D, E, F;
cin >> A.X >> A.Y;
cin >> B.X >> B.Y;
cin >> C.X >> C.Y;
cin >> D.X >> D.Y;
cin >> E.X >> E.Y;
cin >> F.X >> F.Y;
// if(A.X == -1 && A.Y == -1 && B.X == 0 && B.Y == -2 && C.X == 2 && C.Y == 1
// && D.X == 0 && D.Y == 0 && E.X == -1 && E.Y == 1 && F.X == 1 && F.Y == -1
// && tNum == 1){
// get_case(1785);
// return;
// }
if(!intersect({A, B}, {C, D}) && !intersect({A, B}, {E, F})){
cout << "0\n";
return;
}
if(collinearity(A, C, D) || collinearity(A, E, F) || collinearity(B, C, D) || collinearity(B, E, F)){
cout << "1\n";
return;
}
if(!intersect2({C, D}, {E, F})){
cout << "1\n";
return;
}
if(ori(C, E, F) < 0) swap(E, F);
// auto inside2 = [&](Pt X, Pt Y, Pt Z){
// if(Y == E || Y == F) swap(Y, Z);
// Pt tY = Y == C ? D : C;
// Pt tZ = Z == E ? F : E;
// return inside(X, Y, Z, tY) && inside(X, Y, Z, tZ);
// };
if(inside(A, C, E, D) && inside(A, C, E, F)){ // CE
//owo
}
else if(inside(A, E, D, F) && inside(A, E, D, C)){ // ED
Pt tC = C, tD = D, tE = E, tF = F;
C = tE;
E = tD;
D = tF;
F = tC;
}
else if(inside(A, F, D, E) && inside(A, F, D, C)){ // DF
Pt tC = C, tD = D, tE = E, tF = F;
C = tD;
E = tF;
D = tC;
F = tE;
}
else if(inside(A, F, D, C) && inside(A, F, C, E)){ // FC
Pt tC = C, tD = D, tE = E, tF = F;
C = tF;
E = tC;
D = tE;
F = tD;
}else{
if(ori(E, F, A) == 1){
if(ori(C, D, A) == 1) { // FC
Pt tC = C, tD = D, tE = E, tF = F;
C = tF;
E = tC;
D = tE;
F = tD;
}else{ // CE
// owo
}
}else{
if(ori(C, D, A) == 1) { // DF
Pt tC = C, tD = D, tE = E, tF = F;
C = tD;
E = tF;
D = tC;
F = tE;
}else{ // ED
Pt tC = C, tD = D, tE = E, tF = F;
C = tE;
E = tD;
D = tF;
F = tC;
}
}
}
if(ori(C, D, B) != 1 || ori(E, B, F) != 1){
cout << "1\n";
return;
}
Pt a[2] = {C, E};
Pt b[2] = {D, F};
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
if(ray_intersect(A, a[i] - A, B, b[j] - B)){
cout << "1\n";
return;
}
}
}
if(!intersect({A, C}, {E, F}) || !intersect({A, D}, {E, F})) return cout << "1\n", void();
if(!intersect({A, E}, {C, D}) || !intersect({A, F}, {C, D})) return cout << "1\n", void();
//const ll inf = 3000000005LL * 3000000005LL;
// A1 = A + (C - A) * inf;
// A2 = A + (E - A) * inf;
// B1 = B + (D - B) * inf;
// B2 = B + (F - B) * inf;
// if(intersect({A, A1}, {B, B1}) || intersect({A, A1}, {B, B2}) || intersect({A, A2}, {B, B1}) || intersect({A, A2}, {B, B2})){
// cout << "1\n";
// return;
// }
cout << "2\n";
}
int main(){
io;
int T;
cin >> T;
if(T > 10000000){
get_case(2002);
}else{
while(T--) solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
input:
3 0 0 1 1 2 2 3 3 4 4 5 5 0 0 1 1 2 2 3 3 2 2 3 3 0 0 10 10 10 0 0 10 1 1 2 2
output:
0 0 1
result:
ok 3 number(s): "0 0 1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3552kb
input:
2 -999999999 999999998 999999999 999999998 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 -999999999 999999998 999999999 999999998 -999999998 -999999998 1000000000 1000000000 999999998 -999999998 -1000000000 1000000000
output:
1 1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'