Submission #594855

# Submission time Handle Problem Language Result Execution time Memory
594855 2022-07-13T04:54:24 Z 반딧불(#8437) Dragon 2 (JOI17_dragon2) C++17
15 / 100
4000 ms 3788 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct vector2{
    ll x, y;
    vector2(){}
    vector2(ll x, ll y): x(x), y(y){}

    vector2 operator-(const vector2 &r)const{
        return vector2(x-r.x, y-r.y);
    }

    ll cross(vector2 r)const{
        return x*r.y - y*r.x;
    }
};

struct Query{
    int x, y, idx;
    Query(){}
    Query(int x, int y, int idx): x(x), y(y), idx(idx){}
    bool operator<(const Query &r)const{
        return x==r.x ? y<r.y : x<r.x;
    }
};

ll ccw(vector2 a, vector2 b){
    return a.cross(b);
}

ll ccw(vector2 a, vector2 b, vector2 c){
    return (b-a).cross(c-a);
}

inline ll sign(ll x){
    return x>0?1:-1;
}

int n, k, q;
vector2 arr[30002];
int group[30002];
ll calc[30002];
vector<int> groupList[30002];
vector2 ps, pe;


int ans[100002];
Query query[100002];

int main(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld %d", &arr[i].x, &arr[i].y, &group[i]);
        groupList[group[i]].push_back(i);
    }
    scanf("%lld %lld %lld %lld %d", &ps.x, &ps.y, &pe.x, &pe.y, &q);
    for(int i=1; i<=q; i++){
        scanf("%d %d", &query[i].x, &query[i].y);
        query[i].idx = i;
    }

    for(int i=1; i<=n; i++) calc[i] = ccw(ps, pe, arr[i]);
    sort(query+1, query+q+1);
    for(int qi=1; qi<=q; qi++){
        Query p = query[qi];
        if(p.x == query[qi-1].x && p.y == query[qi-1].y){
            ans[p.idx] = ans[query[qi-1].idx];
            continue;
        }
        for(auto X: groupList[p.x]){
            for(auto Y: groupList[p.y]){
//                printf("X %d, Y %d -> %lld, %lld\n", X, Y, ccw(arr[X],arr[Y],ps), ccw(arr[X],arr[Y],pe));
                if(sign(ccw(arr[X], arr[Y], ps)) == sign(ccw(arr[X], arr[Y], pe)) ||
                   (sign(calc[X]) == sign(calc[Y]) && abs(calc[X]) < abs(calc[Y]))) continue;
                ans[p.idx]++;
            }
        }
    }
    for(int i=1; i<=q; i++) printf("%d\n", ans[i]);
}

Compilation message

dragon2.cpp: In function 'int main()':
dragon2.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
dragon2.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%lld %lld %d", &arr[i].x, &arr[i].y, &group[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     scanf("%lld %lld %lld %lld %d", &ps.x, &ps.y, &pe.x, &pe.y, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         scanf("%d %d", &query[i].x, &query[i].y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1108 KB Output is correct
2 Correct 40 ms 1204 KB Output is correct
3 Correct 52 ms 1364 KB Output is correct
4 Correct 50 ms 3680 KB Output is correct
5 Correct 41 ms 3788 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 3 ms 1264 KB Output is correct
8 Correct 8 ms 1108 KB Output is correct
9 Correct 7 ms 1180 KB Output is correct
10 Correct 8 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2166 ms 2736 KB Output is correct
2 Execution timed out 4070 ms 2644 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1108 KB Output is correct
2 Correct 40 ms 1204 KB Output is correct
3 Correct 52 ms 1364 KB Output is correct
4 Correct 50 ms 3680 KB Output is correct
5 Correct 41 ms 3788 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 3 ms 1264 KB Output is correct
8 Correct 8 ms 1108 KB Output is correct
9 Correct 7 ms 1180 KB Output is correct
10 Correct 8 ms 1112 KB Output is correct
11 Correct 2166 ms 2736 KB Output is correct
12 Execution timed out 4070 ms 2644 KB Time limit exceeded
13 Halted 0 ms 0 KB -