제출 #1194252

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

struct Data {
  int l,r;
  vector<int> idx;

  Data(int n) {
    l = 0;
    r = n - 1;
    for (int i = 0; i < n; i++) idx.push_back(i);
  }
  
  Data(int l, int r, vector<int> idx) : l(l), r(r), idx(idx);
};

int* restore_permutation(int n, int w, int r) {
  queue<pair<int,int>> q;
  q.push({0, n - 1});
  while (!q.empty()) {
    auto [start, end] = q.front(); q.pop();
    if (start == end) continue;
    string s(n, '1');
    for (int i = start; i <= end; i++) s[i] = '0';
    int mid = start + (end - start) / 2;
    for (int i = start; i <= mid; i++) {
      string t = s;
      t[i] = '1';
      add_element(t);
    }
    
    q.push({start, mid});
    q.push({mid + 1, end});
  }
  
  compile_set();
  
  queue<Data> q2;
  q2.push(Data(n));
  int ans[n];
  
  while (!q2.empty()) {
    auto curr = q2.front(); q2.pop();
    int start = curr.l, end = curr.r;
    if (start == end) {
      ans[curr.idx[0]] = start;
      continue;
    }
    
    vector<int> left, right;
    string s(n, '1');
    for (auto i: curr.idx) s[i] = '0';
    for (auto i: curr.idx) {
      string t = s;
      t[i] = '1';
      if (check_element(t)) left.push_back(i);
      else right.push_back(i);
    }
    
    int mid = start + (end - start) / 2;
    q2.push(Data(start, mid, left));
    q2.push(Data(mid + 1, end, right));
  }
  
  return ans;
}

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

messy.cpp: In constructor 'Data::Data(int, int, std::vector<int>)':
messy.cpp:14:61: error: expected '{' at end of input
   14 |   Data(int l, int r, vector<int> idx) : l(l), r(r), idx(idx);
      |                                                             ^
messy.cpp: In function 'int* restore_permutation(int, int, int)':
messy.cpp:29:7: error: 'add_element' was not declared in this scope
   29 |       add_element(t);
      |       ^~~~~~~~~~~
messy.cpp:36:3: error: 'compile_set' was not declared in this scope
   36 |   compile_set();
      |   ^~~~~~~~~~~
messy.cpp:56:11: error: 'check_element' was not declared in this scope
   56 |       if (check_element(t)) left.push_back(i);
      |           ^~~~~~~~~~~~~
messy.cpp:65:10: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   65 |   return ans;
      |          ^~~
messy.cpp:40:7: note: declared here
   40 |   int ans[n];
      |       ^~~
messy.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
messy_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~