답안 #833929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833929 2023-08-22T09:33:22 Z maomao90 카멜레온의 사랑 (JOI20_chameleon) C++17
64 / 100
52 ms 2256 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
#include "chameleon.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 1005;

namespace {
    int n;
    int occ[MAXN][MAXN];
    vi adj[MAXN];
    int label[MAXN];
    void dfs(int u) {
        for (int v : adj[u]) {
            if (label[v]) {
                continue;
            }
            label[v] = 3 - label[u];
            dfs(v);
        }
    }
}

void Solve(int N) {
    n = N;
    //vi lid(n), rid(n);
    //iota(ALL(lid), 1);
    //iota(ALL(rid), n + 1);
    vi lid, rid;
    if (n <= 50) {
        REP (i, 1, 2 * n + 1) {
            REP (j, i + 1, 2 * n + 1) {
                if (Query({i, j}) == 1) {
                    adj[i].pb(j);
                    adj[j].pb(i);
                }
            }
        }
        REP (i, 1, 2 * n + 1) {
            if (label[i]) {
                continue;
            }
            label[i] = 1;
            dfs(i);
        }
        REP (i, 1, 2 * n + 1) {
            if (label[i] == 1) {
                lid.pb(i);
            } else {
                rid.pb(i);
            }
        }
    } else {
        REP (i, 1, 2 * n + 1) {
            lid.pb(i);
            if (Query(lid) != SZ(lid)) {
                lid.pop_back();
                rid.pb(i);
            }
        }
    }
    REP (z, 0, 2) {
        for (int i : rid) {
            vi p(ALL(lid));
            p.pb(i);
            int s = Query(p) - SZ(p);
            int lo = 0, hi = n - 1;
            while (lo < hi) {
                int mid = lo + hi >> 1;
                vi p(lid.begin(), lid.begin() + mid + 1);
                p.pb(i);
                int x = Query(p) - SZ(p);
                if (x <= s) {
                    hi = mid;
                } else {
                    lo = mid + 1;
                }
            }
            occ[min(i, lid[hi])][max(i, lid[hi])]++;
            lo = 0, hi = n - 1;
            while (lo < hi) {
                int mid = lo + hi + 1 >> 1;
                vi p(lid.begin() + mid, lid.end());
                p.pb(i);
                int x = Query(p) - SZ(p);
                if (x <= s) {
                    lo = mid;
                } else {
                    hi = mid - 1;
                }
            }
            occ[min(i, lid[lo])][max(i, lid[lo])]++;
        }
        swap(lid, rid);
    }
    REP (i, 1, 2 * n + 1) {
        REP (j, i + 1, 2 * n + 1) {
            if (occ[i][j] >= 2) {
                Answer(i, j);
            }
        }
    }
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:102:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  102 |                 int mid = lo + hi >> 1;
      |                           ~~~^~~~
chameleon.cpp:115:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  115 |                 int mid = lo + hi + 1 >> 1;
      |                           ~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 48 ms 2128 KB Output is correct
4 Correct 41 ms 2244 KB Output is correct
5 Correct 43 ms 2212 KB Output is correct
6 Correct 40 ms 2256 KB Output is correct
7 Correct 40 ms 2128 KB Output is correct
8 Correct 40 ms 2128 KB Output is correct
9 Correct 41 ms 2164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 3 ms 464 KB Output is correct
12 Correct 3 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 41 ms 2256 KB Output is correct
4 Correct 44 ms 2256 KB Output is correct
5 Correct 41 ms 2256 KB Output is correct
6 Correct 44 ms 2256 KB Output is correct
7 Correct 41 ms 2248 KB Output is correct
8 Correct 52 ms 2244 KB Output is correct
9 Correct 40 ms 2256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 48 ms 2128 KB Output is correct
4 Correct 41 ms 2244 KB Output is correct
5 Correct 43 ms 2212 KB Output is correct
6 Correct 40 ms 2256 KB Output is correct
7 Correct 40 ms 2128 KB Output is correct
8 Correct 40 ms 2128 KB Output is correct
9 Correct 41 ms 2164 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 3 ms 464 KB Output is correct
21 Correct 3 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 464 KB Output is correct
25 Correct 2 ms 464 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 41 ms 2256 KB Output is correct
31 Correct 44 ms 2256 KB Output is correct
32 Correct 41 ms 2256 KB Output is correct
33 Correct 44 ms 2256 KB Output is correct
34 Correct 41 ms 2248 KB Output is correct
35 Correct 52 ms 2244 KB Output is correct
36 Correct 40 ms 2256 KB Output is correct
37 Incorrect 4 ms 464 KB Wrong Answer [1]
38 Halted 0 ms 0 KB -