답안 #969517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969517 2024-04-25T09:30:33 Z anango 동굴 (IOI13_cave) C++17
0 / 100
2 ms 860 KB
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long

int tryvec(vector<int> v) {
    int32_t attempt[v.size()];
    for (int i=0; i<v.size(); i++) {
        attempt[i] = v[i];
    }
    int T=tryCombination(attempt);
    if (T==-1) {
        return v.size();
    }
    return T;
}
void ansvec(vector<int> v, vector<int> w) {
    int32_t attempt[v.size()];
    int32_t perm[v.size()];
    for (int i=0; i<v.size(); i++) {
        attempt[i] = v[i];
        perm[i] = w[i];
    }
    answer(attempt, perm);
}

void exploreCave(int32_t N) {
    int n=N;
    vector<int> permutation(n,-1);
    vector<int> answers(n,-1);
    vector<int> current(n,-1);
    for (int cur=0; cur<N; cur++) {
        //find if the intended state is off or on
        current=vector<int>(n,0);
        for (int i=0; i<n; i++) {
            if (answers[i]!=-1) {
                current[i] = answers[i];
            }
        }
        int ans = tryvec(current);
        int ist=-1;
        if (ans==cur) {
            //intended state is 1
            ist=1;
            int l=0;
            int r=N;
            while (l<r) {
                int m=(l+r)/2;
                for (int i=l; i<=m; i++) {
                    if (answers[i]==-1) {
                        current[i] = 1;
                    }
                }
                if (tryvec(current)==cur) {
                    l=m+1;
                    r=r;
                }
                else {
                    l=l;
                    r=m;
                }
            }
            answers[l] = ist;
            permutation[cur] = l;
        }
        else {
            assert(ans==cur+1);
            //intended state is 0
            current=vector<int>(n,1);
            for (int i=0; i<n; i++) {
                if (answers[i]!=-1) {
                    current[i] = answers[i];
                }
            }
            int l=0;
            int r=N;
            while (l<r) {
                int m=(l+r)/2;
                for (int i=l; i<=m; i++) {
                    if (answers[i]==-1) {
                        current[i] = 0;
                    }
                }
                if (tryvec(current)==cur) {
                    l=m+1;
                    r=r;
                }
                else {
                    l=l;
                    r=m;
                }
            }
            ist=0;
            answers[l] = ist;
            permutation[cur] = l;
        }
        
    }
    ansvec(answers, permutation);
}

Compilation message

cave.cpp: In function 'long long int tryvec(std::vector<long long int>)':
cave.cpp:8:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i=0; i<v.size(); i++) {
      |                   ~^~~~~~~~~
cave.cpp: In function 'void ansvec(std::vector<long long int>, std::vector<long long int>)':
cave.cpp:20:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i=0; i<v.size(); i++) {
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 860 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -