Submission #1250901

#TimeUsernameProblemLanguageResultExecution timeMemory
1250901SoMotThanhXuan동굴 (IOI13_cave)C++20
Compilation error
0 ms0 KiB
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define REP(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define mp make_pair
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define Bit(x, i) ((x >> (i)) & 1)
#define Mask(i) (1 << (i))
#define Cnt(x) __builtin_popcount(x)
#define Cntll(x) __builtin_popcountll(x)
#define Ctz(x) __builtin_ctz(x) // so luong so 0 tinh tu ben phai
#define Ctzll(x) __builtin_ctzll(x)
#define Clz(x) __builtin_clz(x) // so luong so 0 tinh tu ben trai
#define Clzll(x) __builtin_clzll(x)
inline bool maximize(int &u, int v){
    return v > u ? u = v, true : false;
}
inline bool minimize(int &u, int v){
    return v < u ? u = v, true : false;
}
inline bool maximizell(long long &u, long long v){
    return v > u ? u = v, true : false;
}
inline bool minimizell(long long &u, long long v){
    return v < u ? u = v, true : false;
}
const int mod = 1e9 + 7;
inline int fastPow(int a, int n){
    if(n == 0) return 1;
    int t = fastPow(a, n >> 1);
    t = 1ll * t * t % mod;
    if(n & 1) t = 1ll * t * a % mod;
    return t;
}
inline void add(int &u, int v){
    u += v;
    if(u >= mod) u -= mod;
}
inline void sub(int &u, int v){
    u -= v;
    if(u < 0) u += mod;
}
const int maxN = 5e3;
const int inf = 1e9;
const long long infll = 1e18;
//int orgs[maxN], orgd[maxN];
//int N;
//int tryCombination(int S[]){
//    int Min = inf;
//    FOR(i, 0, N - 1){
//        if(S[i] != orgs[i]) minimize(Min, orgd[i]);
//    }
//    if(Min != inf) return Min;
//    return -1;
//}
//int s[maxN], d[maxN];
//void answer(int s[], int d[]){
//    FOR(i, 0, N - 1)cout << s[i] << ' ';cout << '\n';
//    FOR(i, 0, N - 1)cout << d[i] << ' ';cout << '\n';
//    FOR(i, 0, N - 1){
//        assert(s[i] == orgs[i]);
//        assert(d[i] == orgd[i]);
//    }
//
////    cout << "ac\n";
//}
void exploreCave(int n){
    memset(d, -1, sizeof(d));
    FOR(i, 0, n - 1){
        // [0, i - 1] doan xong roi
        int l = 0, r = n - 1;
        FOR(i, 0, n - 1)if(d[i] == -1)s[i] = 0;
        int ansi = 0;
        int v = tryCombination(s);
        if(v == i){
            ansi = 1;
            FOR(i, 0, n - 1)if(d[i] == -1)s[i] = 1;
        }else{
            ansi = 0;
        }
//        cerr << i << '\n';
        while(l < r){
//            cerr << l << ' ' << r << '\n';
            int mid = (l + r + 1) >> 1;
            FOR(i, l, mid - 1)if(d[i] == -1)s[i] = 0;
            FOR(i, mid, r)if(d[i] == -1)s[i] = 1;
            int v = tryCombination(s);
            if(v == i){
                if(ansi == 0){
                    l = mid;
                }else r = mid - 1;
            }else{
                if(ansi == 0){
                    r = mid - 1;
                }else l = mid;
            }
        }
        s[l] = ansi;
        d[l] = i;
    }
    answer(s, d);
}
void process(){
    cin >> N;
    FOR(i, 0, N - 1){
        cin >> orgs[i];
    }
    FOR(i, 0, N - 1){
        cin >> orgd[i];
    }
    exploreCave(N);
}

/*
5
0 0 1 1 0
4 1 3 2 0
*/
//#define LOVE "cave"
//int main(){
//    if(fopen(LOVE".inp", "r")){
//        freopen(LOVE".inp", "r", stdin);
//        freopen(LOVE".out", "w", stdout);
//    }
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);
//
//    int t = 1;
////    cin >> t;
//    while(t--)
//        process();
//    cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ;
//    return 0;
//}
//
//

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:72:12: error: 'd' was not declared in this scope
   72 |     memset(d, -1, sizeof(d));
      |            ^
cave.cpp:76:39: error: 's' was not declared in this scope
   76 |         FOR(i, 0, n - 1)if(d[i] == -1)s[i] = 0;
      |                                       ^
cave.cpp:78:32: error: 's' was not declared in this scope
   78 |         int v = tryCombination(s);
      |                                ^
cave.cpp:105:12: error: 's' was not declared in this scope
  105 |     answer(s, d);
      |            ^
cave.cpp: In function 'void process()':
cave.cpp:108:12: error: 'N' was not declared in this scope
  108 |     cin >> N;
      |            ^
cave.cpp:110:16: error: 'orgs' was not declared in this scope
  110 |         cin >> orgs[i];
      |                ^~~~
cave.cpp:113:16: error: 'orgd' was not declared in this scope
  113 |         cin >> orgd[i];
      |                ^~~~