Submission #1516781


Source Code Expand

#include<iostream>
using namespace std;
typedef long long ll;

ll ax, ay, bx, by, n;

bool isIntersect(ll x0, ll y0, ll x1, ll y1){
    if(x0 > x1){
        x0 ^= x1 ^= x0 ^= x1;
        y0 ^= y1 ^= y0 ^= y1;
    }
    return (x0 == x1 ? (ax <= x0 && x0 <= bx ? (min<ll>(y0, y1) - ay) * (bx - ax) < (by - ay) * (x0 - ax) && (by - ay) * (x0 - ax) < (max<ll>(y0, y1) - ay) * (bx - ax) : 0) : (x1 < ax || bx < x0 ? 0 : ((x1 - x0) * (by - ay) * (max<ll>(x0, ax) - ax) + ay * (x1 - x0) * (bx - ax) > (y1 - y0) * (bx - ax) * (max<ll>(x0, ax) - x0) + y0 * (bx - ax) * (x1 - x0)) != ((x1 - x0) * (by - ay) * (min<ll>(x1, bx) - ax) + ay * (x1 - x0) * (bx - ax) > (y1 - y0) * (bx - ax) * (min<ll>(x1, bx) - x0) + y0 * (bx - ax) * (x1 - x0)) ));
}

int main(){
    cin >> ax >> ay >> bx >> by >> n;
    ll xy[n][2];
    for(ll i = 0; i < n; ++i) cin >> xy[i][(ax != bx ? 0 : 1)] >> xy[i][(ax != bx ? 1 : 0)];
    if(ax == bx){
        ax ^= ay ^= ax ^= ay;
        bx ^= by ^= bx ^= by;
    }
    if(ax > bx){
        ax ^= bx ^= ax ^= bx;
        ay ^= by ^= ay ^= by;
    }
    ll count = 0;
    for(ll i = 0; i < n; ++i){
        if(isIntersect(xy[i][0], xy[i][1], xy[(i + 1 == n ? 0 : i + 1)][0], xy[(i + 1 == n ? 0 : i + 1)][1])){
            ++count;
        }
    }
    cout << 1 + count / 2 << endl;
    return 0;
}

Submission Info

Submission Time
Task D - 一刀両断
User kcvlex
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1346 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 32
Set Name Test Cases
All 00_sample_00.txt, 00_sample_01.txt, 10_rand_00.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 10_rand_06.txt, 10_rand_07.txt, 10_rand_08.txt, 10_rand_09.txt, 10_rand_10.txt, 10_rand_11.txt, 10_rand_12.txt, 10_rand_13.txt, 10_rand_14.txt, 10_rand_15.txt, 10_rand_16.txt, 10_rand_17.txt, 10_rand_18.txt, 10_rand_19.txt, 10_rand_20.txt, 10_rand_21.txt, 10_rand_22.txt, 10_rand_23.txt, 10_rand_24.txt, 10_rand_25.txt, 10_rand_26.txt, 10_rand_27.txt, 10_rand_28.txt, 10_rand_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 256 KB
00_sample_01.txt AC 1 ms 256 KB
10_rand_00.txt AC 1 ms 256 KB
10_rand_01.txt AC 1 ms 256 KB
10_rand_02.txt AC 1 ms 256 KB
10_rand_03.txt AC 1 ms 256 KB
10_rand_04.txt AC 1 ms 256 KB
10_rand_05.txt AC 1 ms 256 KB
10_rand_06.txt AC 1 ms 256 KB
10_rand_07.txt AC 1 ms 256 KB
10_rand_08.txt AC 1 ms 256 KB
10_rand_09.txt AC 1 ms 256 KB
10_rand_10.txt AC 1 ms 256 KB
10_rand_11.txt AC 1 ms 256 KB
10_rand_12.txt AC 1 ms 256 KB
10_rand_13.txt AC 1 ms 256 KB
10_rand_14.txt AC 1 ms 256 KB
10_rand_15.txt AC 1 ms 256 KB
10_rand_16.txt AC 1 ms 256 KB
10_rand_17.txt AC 1 ms 256 KB
10_rand_18.txt AC 1 ms 256 KB
10_rand_19.txt AC 1 ms 256 KB
10_rand_20.txt AC 1 ms 256 KB
10_rand_21.txt AC 1 ms 256 KB
10_rand_22.txt AC 1 ms 256 KB
10_rand_23.txt AC 1 ms 256 KB
10_rand_24.txt AC 1 ms 256 KB
10_rand_25.txt AC 1 ms 256 KB
10_rand_26.txt AC 1 ms 256 KB
10_rand_27.txt AC 1 ms 256 KB
10_rand_28.txt AC 1 ms 256 KB
10_rand_29.txt AC 1 ms 256 KB