제출 #648489

#제출 시각아이디문제언어결과실행 시간메모리
648489PoonYaPatUnscrambling a Messy Bug (IOI16_messy)C++14
컴파일 에러
0 ms0 KiB
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;

int ni,a[130];

void build(int l, int r) {
    if (l==r) return;
    string st,ed;
    for (int i=0; i<l; ++i) st+="1";
    for (int i=r+1; i<ni; ++i) ed+="1";

    int mid=(l+r)/2;
    for (int i=l; i<=mid; ++i) {
        string h;
        for (int j=l; j<=r; ++j) {
            if (j==i) h+="1";
            else h+="0";
        }
        add_element(st+h+ed);
    }
    build(l,mid);
    build(mid+1,r);
}

void check(int l, int r, vector<int> v) { //in range l to r, what can it change to
    if (l==r) {
        a[v[0]]=l;
        return;
    }
    vector<int> left,right;
    string test;
    for (int i=0; i<ni; ++i) test+="1";
    for (auto s : v) test[s]='0';
    for (int i=0; i<ni; ++i) {
        if (test[i]=='0') {
            test[i]='1';
            if (check_element(test)) left.push_back(i);
            else right.push_back(i);
            test[i]='0';
        }
    }
    int mid=(l+r)/2;
    check(l,mid,left);
    check(mid+1,r,right);
}

vector<int> restore_permutation(int N, int w, int r) {
    ni=N;
    build(0,ni-1);
    compile_set();
    vector<int> v;
    for (int i=0; i<n; ++i) v.push_back(i);
    check(0,ni-1,v);
    vector<int> ans;
    for (int i=0; i<n; ++i) ans.push_back(a[i]);
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:53:21: error: 'n' was not declared in this scope
   53 |     for (int i=0; i<n; ++i) v.push_back(i);
      |                     ^
messy.cpp:56:21: error: 'n' was not declared in this scope
   56 |     for (int i=0; i<n; ++i) ans.push_back(a[i]);
      |                     ^