답안 #972712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972712 2024-05-01T04:18:58 Z steveonalex 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
37 ms 600 KB
#include <bits/stdc++.h>
#include "chameleon.h"
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }
 
// namespace Grader{
//     int n;
//     vector<int> Y, C, L;
//     vector<int> check;
//     int o_cnt, ans;
 
//     int Query(const vector<int> &p){
//         o_cnt++;
//         vector<bool> state(n * 2 + 1);
//         for(int i: p) state[i] = 1;
//         vector<bool> color(n*2+1);
//         for(int i: p){
//             if (state[L[i]]) color[C[L[i]]] = 1;
//             else color[C[i]] = 1;
//         }
 
//         int ans = 0;
//         for(int i = 1; i<=2*n; ++i) ans += color[i];
//         return ans;
//     }
 
//     void Answer(int x, int y){
//         // cout << "! " << x << " " << y << "\n";
//         if (C[x] != C[y]) ans = false;
//         check[x]++; check[y]++;
//     }

    void DnC(vector<vector<int>> &graph, vector<int> S){
        vector<int> X, Y;
        for(int i: S){
            X.push_back(i);
            if (X.size() > 1 && Query(X) < X.size()){
                X.pop_back();
                Y.push_back(i);
            }
        }
        for(int i: Y){
            vector<int> tmp = X;
            while(true){
                int l = 0, r = tmp.size() - 1;
                while(l < r){
                    int mid = (l + r) >> 1;
                    vector<int> ask;
                    for(int i = 0; i<=mid; ++i) ask.push_back(tmp[i]);
                    ask.push_back(i);
                    if (Query(ask) < ask.size()) r = mid;
                    else l = mid + 1;
                }
                int u = i, v = tmp[l];
                tmp.erase(tmp.begin() + l);
                graph[u].push_back(v);
                graph[v].push_back(u);

                vector<int> ask = tmp; ask.push_back(i);
                if (graph[i].size() < 3 && Query(ask) < ask.size()) continue;
                break;
            }
        }
        if (Y.size()) DnC(graph, Y);
    }
 
    void Solve(int n){
        vector<vector<int>> graph(n*2+1);
        vector<int> X;
        for(int i =1; i<=2*n; ++i) X.push_back(i);

        DnC(graph, X);

        for(int i = 1; i<=2*n; ++i) if (graph[i].size() != 1){
            pair<int, int> legit = {-1, -1};
            for(int j = 0; j < 3; ++j) for(int k = j + 1; k < 3; ++k){
                vector<int> ask = {i, graph[i][j], graph[i][k]};
                if (Query(ask) == 1) {
                    legit = {graph[i][j], graph[i][k]};
                    break;
                }
            }

            graph[i] = {legit.first, legit.second};
        }

        for(int i = 1; i<=2*n; ++i) sort(ALL(graph[i]));
        for(int i = 1; i<=2*n; ++i){
            for(int j: graph[i]) if (j > i){
                if (binary_search(ALL(graph[j]), i)) {
                    Answer(i, j);
                }
            }
        }
    }
 
//     pair<bool, int> run_test(int _n){
//         n = _n;
//         Y.resize(n * 2 + 1); L = C = Y;
//         for(int i= 1; i<=2*n; ++i) cin >> Y[i];
//         for(int i= 1; i<=2*n; ++i) cin >> C[i];
//         for(int i= 1; i<=2*n; ++i) cin >> L[i];
//         o_cnt = 0; ans = 1;
//         check = vector<int>(2*n+1);
 
//         Solve(n);
 
//         if (*max_element(1+ALL(check)) != 1 || *min_element(1+ALL(check)) != 1) ans = false;
//         return {ans, o_cnt};
//     }
// }
 
// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
//     freopen("input.inp", "r", stdin);
//     // freopen("input.inp", "w", stdout);
 
//     // int n; cin >> n;
//     // vector<int> Y(n*2+1), C(n*2+1), L(n*2+1);
//     // for(int i= 1; i<=2*n; ++i) cin >> Y[i];
//     // for(int i= 1; i<=2*n; ++i) cin >> C[i];
//     // for(int i= 1; i<=2*n; ++i) cin >> L[i];
 
//     // int m = 166;
 
//     // cout << n*m << "\n";
//     // for(int i = 1; i<=2*n*m; ++i) cout << (i > n * m) << " "; cout << "\n";
//     // for(int j = 0; j < m; ++j) for(int i= 1; i<=3; ++i)
//     //     cout << j * n + C[i] << " "; cout << "\n";
//     // for(int j = 0; j < m; ++j) for(int i= 4; i<=6; ++i)
//     //     cout << j * n + C[i] << " "; cout << "\n";
//     // for(int j = 0; j < m; ++j) for(int i= 1; i<=3; ++i)
//     //     cout << j * n + n * (m-1) + L[i] << " "; cout << "\n";
//     // for(int j = 0; j < m; ++j) for(int i= 4; i<=6; ++i)
//     //     cout << j * n + L[i] << " "; cout << "\n";
 
 
 
 
//     int n; cin >> n;
//     pair<bool, int> verdict = Grader::run_test(n);
//     if (verdict.first) cout << "AC\n";
//     else cout << "WA\n";
 
//     cout << "Total operation count: " << verdict.second << "\n";
 
//     return 0;
// }

Compilation message

chameleon.cpp: In function 'void DnC(std::vector<std::vector<int> >&, std::vector<int>)':
chameleon.cpp:78:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             if (X.size() > 1 && Query(X) < X.size()){
      |                                 ~~~~~~~~~^~~~~~~~~~
chameleon.cpp:92:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |                     if (Query(ask) < ask.size()) r = mid;
      |                         ~~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:101:55: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |                 if (graph[i].size() < 3 && Query(ask) < ask.size()) continue;
      |                                            ~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 556 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 14 ms 344 KB Output is correct
4 Correct 14 ms 520 KB Output is correct
5 Correct 14 ms 524 KB Output is correct
6 Correct 18 ms 600 KB Output is correct
7 Correct 14 ms 496 KB Output is correct
8 Correct 15 ms 344 KB Output is correct
9 Correct 14 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 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 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 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 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 35 ms 516 KB Output is correct
4 Correct 35 ms 344 KB Output is correct
5 Correct 35 ms 344 KB Output is correct
6 Correct 37 ms 600 KB Output is correct
7 Correct 36 ms 344 KB Output is correct
8 Correct 35 ms 344 KB Output is correct
9 Correct 35 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 556 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 14 ms 344 KB Output is correct
4 Correct 14 ms 520 KB Output is correct
5 Correct 14 ms 524 KB Output is correct
6 Correct 18 ms 600 KB Output is correct
7 Correct 14 ms 496 KB Output is correct
8 Correct 15 ms 344 KB Output is correct
9 Correct 14 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 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 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 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 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 35 ms 516 KB Output is correct
31 Correct 35 ms 344 KB Output is correct
32 Correct 35 ms 344 KB Output is correct
33 Correct 37 ms 600 KB Output is correct
34 Correct 36 ms 344 KB Output is correct
35 Correct 35 ms 344 KB Output is correct
36 Correct 35 ms 344 KB Output is correct
37 Correct 31 ms 344 KB Output is correct
38 Correct 14 ms 344 KB Output is correct
39 Correct 36 ms 516 KB Output is correct
40 Correct 32 ms 344 KB Output is correct
41 Correct 32 ms 344 KB Output is correct
42 Correct 14 ms 344 KB Output is correct
43 Correct 35 ms 520 KB Output is correct
44 Correct 32 ms 344 KB Output is correct
45 Correct 32 ms 344 KB Output is correct