답안 #384882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384882 2021-04-02T14:42:37 Z innocentkitten Park (BOI16_park) C++14
100 / 100
1430 ms 102028 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define H 2021

using namespace std;

typedef pair<long long int,long long int> pii;
typedef pair<pii,long long int> circ;

int N,M,W,L;
circ C[H]; // nodes 2001, 2002, 2003, 2004 are SENW borders
vector<circ> process;
vector<circ> offline;
bool ret[100010][5];
int S[H];
int P[H];
bool adj[4][4];
bool reach[5][5];

bool sz(circ a, circ b) {
    return a.f.f < b.f.f;
}

bool re(circ a, circ b) {
    return a.s < b.s;
}

int eval(int a, int b) {
    if (b > 2000) return eval(b,a);
    if (a == 2001) return C[b].f.s-C[b].s;
    if (a == 2002) return W-C[b].f.f-C[b].s;
    if (a == 2003) return L-C[b].f.s-C[b].s;
    if (a == 2004) return C[b].f.f-C[b].s;
    return (int)(1LL*sqrt((C[a].f.f-C[b].f.f)*(C[a].f.f-C[b].f.f)
    +1LL*(C[a].f.s-C[b].f.s)*(C[a].f.s-C[b].f.s))-C[a].s-C[b].s);
    // not sure if they want floor or ceil, so i'm keeping it
    // this way for now
}

int pp(int x) {
	if (P[x]==x) return x;
    return (P[x] = pp(P[x]));
}

void un(int a, int b) {
	a = pp(a);
	b = pp(b);
	if (a == b) return;
	if (S[a] > S[b]) swap(a,b);
	S[b] += S[a];
	P[a] = b;
}

int main() {
    cin>>N>>M>>W>>L;
    for (int i = 0; i < H; i++) {
        S[i] = 1; P[i] = i;
    }
    for (int i = 0; i < N; i++) {
        int a,b,r; cin>>a>>b>>r;
        C[i]=mp(mp(a,b),r);
        for (int j = 2001; j < 2005; j++) {
            process.pb(mp(mp(j,i),eval(i,j)));
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            process.pb(mp(mp(i,j),eval(i,j)));
        }
    }
    sort(process.begin(),process.end(),re);
    for (int i = 0; i < M; i++) {
        int s,p; cin >> s >> p;
        offline.pb(mp(mp(s,p),i));
    }
    sort(offline.begin(),offline.end(),sz);
    int point=0;
    for (int i = 0; i < M; i++) {
        circ quer = offline[i];
        while ((point < process.size())
                && (process[point].s
                < 2*quer.f.f)) {
            un(process[point].f.f,process[point].f.s);
            point++;
        }
        for (int x = 0; x < 4; x++) {
            for (int y = x+1; y < 4; y++) {
                adj[x][y]=(pp(x+2001)==pp(y+2001));
                adj[y][x]=adj[x][y];
            }
        }
        reach[1][1] = true;
        reach[2][2] = true;
        reach[3][3] = true;
        reach[4][4] = true;
        reach[1][2] = !(adj[0][1]||adj[0][2]||adj[0][3]);
        reach[2][1] = reach[1][2];
        reach[2][3] = !(adj[1][0]||adj[1][2]||adj[1][3]);
        reach[3][2] = reach[2][3];
        reach[3][4] = !(adj[2][0]||adj[2][1]||adj[2][3]);
        reach[4][3] = reach[3][4];
        reach[4][1] = !(adj[3][0]||adj[3][1]||adj[3][2]);
        reach[1][4] = reach[4][1];
        reach[1][3] = !(adj[0][2]||adj[0][3]||adj[1][2]||adj[1][3]);
        reach[3][1] = reach[1][3];
        reach[2][4] = !(adj[0][1]||adj[0][2]||adj[3][1]||adj[3][2]);
        reach[4][2] = reach[2][4];
        for (int x = 1; x < 5; x++) {
            ret[quer.s][x]=(reach[quer.f.s][x]);
        }
    }
    for (int i = 0; i < M; i++) {
        for (int x = 1; x < 5; x++) {
            if (ret[i][x]) cout << x;
        }
        cout << endl;
    }
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         while ((point < process.size())
      |                 ~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1116 ms 99056 KB Output is correct
2 Correct 1120 ms 99184 KB Output is correct
3 Correct 1106 ms 99056 KB Output is correct
4 Correct 1106 ms 99056 KB Output is correct
5 Correct 1112 ms 99236 KB Output is correct
6 Correct 1095 ms 99056 KB Output is correct
7 Correct 1076 ms 99184 KB Output is correct
8 Correct 1083 ms 99056 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 4700 KB Output is correct
2 Correct 315 ms 5724 KB Output is correct
3 Correct 318 ms 5852 KB Output is correct
4 Correct 317 ms 5724 KB Output is correct
5 Correct 321 ms 5724 KB Output is correct
6 Correct 327 ms 5980 KB Output is correct
7 Correct 312 ms 4852 KB Output is correct
8 Correct 305 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1116 ms 99056 KB Output is correct
2 Correct 1120 ms 99184 KB Output is correct
3 Correct 1106 ms 99056 KB Output is correct
4 Correct 1106 ms 99056 KB Output is correct
5 Correct 1112 ms 99236 KB Output is correct
6 Correct 1095 ms 99056 KB Output is correct
7 Correct 1076 ms 99184 KB Output is correct
8 Correct 1083 ms 99056 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 322 ms 4700 KB Output is correct
12 Correct 315 ms 5724 KB Output is correct
13 Correct 318 ms 5852 KB Output is correct
14 Correct 317 ms 5724 KB Output is correct
15 Correct 321 ms 5724 KB Output is correct
16 Correct 327 ms 5980 KB Output is correct
17 Correct 312 ms 4852 KB Output is correct
18 Correct 305 ms 4956 KB Output is correct
19 Correct 1430 ms 101900 KB Output is correct
20 Correct 1408 ms 101932 KB Output is correct
21 Correct 1415 ms 102028 KB Output is correct
22 Correct 1396 ms 101772 KB Output is correct
23 Correct 1403 ms 101804 KB Output is correct
24 Correct 1394 ms 101820 KB Output is correct