답안 #919402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919402 2024-01-31T17:36:44 Z winter0101 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
40 ms 1620 KB
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
mt19937_64 rng(310197);
const int maxn = 1e3 + 9;
vector<int>a[maxn];
bool edg[maxn][maxn];
bool vis[maxn];
bool type[maxn];
void dfs(int u) {
    for (auto v : a[u]) {
        if (vis[v])
            continue;

        type[v] = (type[u] ^ 1);
        vis[v] = 1;
        dfs(v);
    }
}
void Solve(int n) {
    vector<int>white, black;
    for2(i, 2 * n, 1) {
        if (white.empty() && black.empty()) {
            white.pb(i);
            continue;
        }

        if (1) {
            int lst = -1;

            while (true) {
                int l = lst + 1, r = sz(white) - 1, ans = -1;
                vector<int>ck = {i};
                for1(j, lst + 1, r)ck.pb(white[j]);

                if (Query(ck) == sz(ck))
                    break;

                while (l <= r) {
                    int mid = (l + r) / 2;
                    vector<int>check;
                    for1(j, lst + 1, mid) {
                        check.pb(white[j]);
                    }
                    check.pb(i);

                    if (sz(check) > Query(check)) {
                        ans = mid;
                        r = mid - 1;
                    } else
                        l = mid + 1;
                }

                if (ans == -1)
                    break;

                lst = ans;
                a[i].pb(white[ans]);
                a[white[ans]].pb(i);
                //cout<<i<<" "<<white[ans]<<'\n';
            }
        }

        swap(black, white);

        if (1) {
            int lst = -1;

            while (true) {
                int l = lst + 1, r = sz(white) - 1, ans = -1;
                vector<int>ck = {i};
                for1(j, lst + 1, r)ck.pb(white[j]);

                if (Query(ck) == sz(ck))
                    break;

                while (l <= r) {
                    int mid = (l + r) / 2;
                    vector<int>check;
                    for1(j, lst + 1, mid) {
                        check.pb(white[j]);
                    }
                    check.pb(i);

                    if (sz(check) > Query(check)) {
                        ans = mid;
                        r = mid - 1;
                    } else
                        l = mid + 1;
                }

                if (ans == -1)
                    break;

                lst = ans;
                a[i].pb(white[ans]);
                a[white[ans]].pb(i);
                //cout<<i<<" "<<white[ans]<<'\n';
            }
        }

        white.clear();
        black.clear();
        for1(j, i, 2 * n) {
            vis[j] = 0;
        }
        for1(j, i, 2 * n) {
            if (!vis[j]) {
                vis[j] = 1;
                type[j] = 0;
                dfs(j);
            }
        }
        for1(j, i, 2 * n) {
            if (!type[j])
                white.pb(j);
            else
                black.pb(j);
        }
    }
    //cout<<"ya";
    vector<pii>ans;
    for1(i, 1, 2 * n) {
        if (sz(a[i]) == 1) {
            for (auto v : a[i]) {
                //cout<<i<<" "<<v<<'\n';
                edg[v][i] = edg[i][v] = 1;
            }
        } else {
            vector<int>check;
            check.pb(i);
            for1(j, 0, sz(a[i]) - 1) {
                check.pb(a[i][j]);
                for1(k, j + 1, sz(a[i]) - 1) {
                    check.pb(a[i][k]);

                    if (Query(check) == 1) {
                        edg[i][a[i][j]] = 1;
                        edg[i][a[i][k]] = 1;
                    }

                    check.pop_back();
                }
                check.pop_back();
            }
        }
    }
    for1(i, 1, 2 * n) {
        for1(j, i + 1, 2 * n) {
            if (edg[i][j] && edg[j][i]) {
                Answer(i, j);
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 19 ms 1368 KB Output is correct
4 Correct 24 ms 1360 KB Output is correct
5 Correct 19 ms 1368 KB Output is correct
6 Correct 19 ms 1368 KB Output is correct
7 Correct 20 ms 1620 KB Output is correct
8 Correct 20 ms 1368 KB Output is correct
9 Correct 21 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 36 ms 1528 KB Output is correct
4 Correct 36 ms 1360 KB Output is correct
5 Correct 35 ms 1316 KB Output is correct
6 Correct 35 ms 1360 KB Output is correct
7 Correct 36 ms 1360 KB Output is correct
8 Correct 39 ms 1360 KB Output is correct
9 Correct 36 ms 1296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 19 ms 1368 KB Output is correct
4 Correct 24 ms 1360 KB Output is correct
5 Correct 19 ms 1368 KB Output is correct
6 Correct 19 ms 1368 KB Output is correct
7 Correct 20 ms 1620 KB Output is correct
8 Correct 20 ms 1368 KB Output is correct
9 Correct 21 ms 1360 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 36 ms 1528 KB Output is correct
31 Correct 36 ms 1360 KB Output is correct
32 Correct 35 ms 1316 KB Output is correct
33 Correct 35 ms 1360 KB Output is correct
34 Correct 36 ms 1360 KB Output is correct
35 Correct 39 ms 1360 KB Output is correct
36 Correct 36 ms 1296 KB Output is correct
37 Correct 38 ms 1360 KB Output is correct
38 Correct 21 ms 1552 KB Output is correct
39 Correct 37 ms 1360 KB Output is correct
40 Correct 40 ms 1360 KB Output is correct
41 Correct 38 ms 1284 KB Output is correct
42 Correct 20 ms 1368 KB Output is correct
43 Correct 36 ms 1360 KB Output is correct
44 Correct 40 ms 1552 KB Output is correct
45 Correct 39 ms 1316 KB Output is correct