제출 #648890

#제출 시각아이디문제언어결과실행 시간메모리
648890JANCARAPAN동굴 (IOI13_cave)C++17
0 / 100
544 ms404 KiB
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x);
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr <<__func__<<":"<<" [" << #x << "] = ["; _print(x); /*cerr << "\e[39m" << endl;*/
#else
#define dbg(x...)
#endif


// int tryCombination(int a[4]) {
//     int sm = 0;
//     if (a[2] == 1) {
//         sm++;
//         if (a[1] == 1) {
//             sm++;
//             if (a[3] == 0) {
//                 sm++;
//                 if (a[0] == 1) {
//                     sm++;
//                 }
//             }
//         }
//     }
//     if (sm == 4) return -1;
//     else return sm;
// }


void exploreCave(int n) {
    int pos[n], con[n], used[n];

    for (int i=0; i<n; i++) {
        // per a cada porta faig bs dels interruptors
        int l = 0, r = n - 1;
        int res = n - 1;
        int on = (tryCombination(pos) == i);

        while (l <= r) {
            int m = l + (r - l) / 2;
            bool can = 0;
 
            for (int j=0; j<n; j++) {
                if (used[j]) continue;
                if (j>=l && j<=m) {
                    pos[j] = on;
                } else {
                    pos[j] = 1 - on;
                }
            }


            // for (auto x : pos) cerr << x << " ";
            // cerr << endl;

            int ans = tryCombination(pos);
            
            if (ans >= i + 1 || ans == -1) {
                can = 1;
            } 

            for (int j=0; j<n; j++) {
                if (used[j]) continue;
                pos[j] = 0;
            }

            if (can) {
                r = m - 1;
                res = m;
            } else {
                l = m + 1;
            }
            //cerr << m << " " << l << " " << r << endl;
        
        }
       //dbg(res, on)
        
        used[res] = 1;
        pos[res] = on;

        con[res] = i;
    }
    answer(pos, con);
    
    // for (auto x : pos) cout << x << " ";
    // cout << endl << endl;
    // for (auto x : con) cout << x <<" ";
    // cout << endl;
}

// int main() {
//     exploreCave(4);
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...