답안 #424396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424396 2021-06-11T21:51:22 Z duality Park (JOI17_park) C++11
100 / 100
604 ms 1988 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "park.h"

vi order;
int seen[1400];
int P[1400];
int ask(int A,int B,int *P) {
    if (A > B) swap(A,B);
    return Ask(A,B,P);
}
int answer(int A,int B) {
    if (A > B) swap(A,B);
    Answer(A,B);
    return 0;
}
int add(int u,int N) {
    int i;
    for (i = 0; i < N; i++) P[i] = 0;
    for (i = 0; i < order.size(); i++) P[order[i]] = 1;
    P[u] = 1;
    if (ask(0,u,P)) order.pb(u),seen[u] = 1;
    else {
        vi o;
        for (i = 0; i < N; i++) {
            if (!seen[i] && (i != u)) o.pb(i);
        }
        int l = 0,r = o.size()-1;
        while (l < r) {
            int m = (l+r) / 2;

            for (i = 0; i < N; i++) P[i] = 0;
            for (i = 0; i < order.size(); i++) P[order[i]] = 1;
            P[u] = 1;
            for (i = 0; i <= m; i++) P[o[i]] = 1;
            if (ask(0,u,P)) r = m;
            else l = m+1;
        }
        add(o[l],N);
        add(u,N);
    }
    return 0;
}
vi adjList[1400];
vi e,c;
bool comp(int a,int b) {
    return seen[a] < seen[b];
}
int visited[1400];
int doDFS(int u,int p) {
    if (visited[u]) return 0;
    int i;
    c.pb(u);
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) doDFS(v,u);
    }
    return 0;
}
int getEdges(vi v,int u,int N) {
    int i;
    sort(v.begin(),v.end(),comp);
    for (i = 0; i < N; i++) P[i] = 0;
    for (i = 0; i < v.size(); i++) P[v[i]] = 1;
    P[u] = 1;
    if (!ask(v[0],u,P)) return 0;
    int l = 0,r = v.size()-1;
    while (l < r) {
        int m = (l+r) / 2;

        for (i = 0; i < N; i++) P[i] = 0;
        for (i = 0; i <= m; i++) P[v[i]] = 1;
        P[u] = 1;
        if (ask(v[0],u,P)) r = m;
        else l = m+1;
    }
    e.pb(v[l]),visited[v[l]] = 1;
    vector<vi> com;
    for (i = 0; i < adjList[v[l]].size(); i++) {
        doDFS(adjList[v[l]][i],-1);
        if (!c.empty()) com.pb(c);
        c.clear();
    }
    for (i = 0; i < com.size(); i++) getEdges(com[i],u,N);
    return 0;
}
void Detect(int T,int N) {
    int i;
    order.pb(0),seen[0] = 1;
    for (i = 1; i < N; i++) {
        if (!seen[i]) add(i,N);
    }
    vi v;
    for (i = 0; i < N; i++) seen[order[i]] = i;
    for (i = 1; i < N; i++) {
        int u = order[i];
        fill(visited,visited+N,0);
        v.pb(order[i-1]);
        getEdges(v,u,N);
        int f = 1;
        while (!e.empty()) {
            if (f) adjList[e.back()].pb(u),adjList[u].pb(e.back()),f = 0;
            answer(e.back(),u);
            e.pop_back();
        }
    }
}

Compilation message

park.cpp: In function 'int add(int, int)':
park.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (i = 0; i < order.size(); i++) P[order[i]] = 1;
      |                 ~~^~~~~~~~~~~~~~
park.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             for (i = 0; i < order.size(); i++) P[order[i]] = 1;
      |                         ~~^~~~~~~~~~~~~~
park.cpp: In function 'int doDFS(int, int)':
park.cpp:108:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for (i = 0; i < adjList[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
park.cpp: In function 'int getEdges(vi, int, int)':
park.cpp:118:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for (i = 0; i < v.size(); i++) P[v[i]] = 1;
      |                 ~~^~~~~~~~~~
park.cpp:133:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for (i = 0; i < adjList[v[l]].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~~~~
park.cpp:138:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |     for (i = 0; i < com.size(); i++) getEdges(com[i],u,N);
      |                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 12 ms 416 KB Output is correct
3 Correct 11 ms 460 KB Output is correct
4 Correct 20 ms 464 KB Output is correct
5 Correct 38 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 604 ms 756 KB Output is correct
2 Correct 213 ms 616 KB Output is correct
3 Correct 284 ms 1988 KB Output is correct
4 Correct 589 ms 772 KB Output is correct
5 Correct 572 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 676 KB Output is correct
2 Correct 402 ms 612 KB Output is correct
3 Correct 420 ms 600 KB Output is correct
4 Correct 379 ms 728 KB Output is correct
5 Correct 433 ms 616 KB Output is correct
6 Correct 406 ms 596 KB Output is correct
7 Correct 401 ms 612 KB Output is correct
8 Correct 405 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 452 KB Output is correct
2 Correct 453 ms 536 KB Output is correct
3 Correct 456 ms 580 KB Output is correct
4 Correct 495 ms 580 KB Output is correct
5 Correct 483 ms 700 KB Output is correct
6 Correct 460 ms 700 KB Output is correct
7 Correct 526 ms 588 KB Output is correct
8 Correct 459 ms 580 KB Output is correct
9 Correct 471 ms 580 KB Output is correct
10 Correct 503 ms 588 KB Output is correct
11 Correct 488 ms 812 KB Output is correct
12 Correct 443 ms 576 KB Output is correct
13 Correct 538 ms 588 KB Output is correct
14 Correct 475 ms 800 KB Output is correct
15 Correct 543 ms 588 KB Output is correct
16 Correct 414 ms 848 KB Output is correct
17 Correct 573 ms 768 KB Output is correct
18 Correct 466 ms 720 KB Output is correct
19 Correct 566 ms 608 KB Output is correct
20 Correct 474 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 510 ms 668 KB Output is correct
2 Correct 493 ms 580 KB Output is correct
3 Correct 443 ms 580 KB Output is correct
4 Correct 491 ms 840 KB Output is correct
5 Correct 485 ms 708 KB Output is correct
6 Correct 581 ms 1012 KB Output is correct
7 Correct 547 ms 696 KB Output is correct
8 Correct 504 ms 744 KB Output is correct
9 Correct 506 ms 636 KB Output is correct
10 Correct 468 ms 632 KB Output is correct
11 Correct 500 ms 548 KB Output is correct
12 Correct 520 ms 724 KB Output is correct
13 Correct 466 ms 680 KB Output is correct
14 Correct 526 ms 744 KB Output is correct
15 Correct 425 ms 588 KB Output is correct
16 Correct 412 ms 708 KB Output is correct
17 Correct 582 ms 680 KB Output is correct
18 Correct 408 ms 588 KB Output is correct