답안 #722292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722292 2023-04-11T17:17:37 Z tvladm2009 Secret Permutation (RMI19_permutation) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "permutation.h"

using namespace std;

typedef long long ll;

const int N_MAX = 256;

mt19937 rnd(time(NULL));

vector <int> sol, questions;
bool used[N_MAX + 2];

bool found = 0;

void dfs(int pos, int N) {
    if (pos == N - 1) {
        if (abs(sol[0] - sol[pos]) == questions[pos]) {
            found = 1;
        }
        return;
    }
    int next = sol[pos] - questions[pos];
    if (1 <= next && next <= N && !used[next]) {
        sol.push_back(next);
        used[next] = 1;
        dfs(pos + 1, N);
        if (found == 1) {
            return;
        }
        used[next] = 0;
        sol.pop_back();
    }
    next = sol[pos] + questions[pos];
    if (1 <= next && next <= N && !used[next]) {
        sol.push_back(next);
        used[next] = 1;
        dfs(pos + 1, N);
        if (found == 1) {
            return;
        }
        used[next] = 0;
        sol.pop_back();
    }
}

void solve(int N) {
    vector <int> V;
    for (int i = 1; i <= N; i++) {
        V.push_back(i);
    }
    random_shuffle(V.begin(), V.end(), rnd);
    vector <int> C = V;
    questions.clear();
    for (int i = 1; i <= N; i++) {
        rotate(V.begin(), V.begin() + 1, V.end());
        questions.push_back(query(V));
    }
    int sum = 0;
    for (int it : questions) {
        sum += it;
    }
    sum /= N - 1;
    for (int &it : questions) {
        it = sum - it;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            used[j] = 0;
        }
        sol.clear();
        sol.push_back(i);
        used[i] = 1;
        found = 0;
        dfs(0, N);
        if (found == 1) {
            vector <int> ret(N);
            for (int j = 0; j < N; j++) {
                ret[C[j] - 1] = sol[j];
            }
            answer(ret);
            return;
        }
    }
}

Compilation message

In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from permutation.cpp:1:
/usr/include/c++/10/bits/stl_algo.h: In instantiation of 'void std::random_shuffle(_RAIter, _RAIter, _Generator&&) [with _RAIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Generator = std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&]':
permutation.cpp:53:43:   required from here
/usr/include/c++/10/bits/stl_algo.h:4636:48: error: no match for call to '(std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>) (__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
 4636 |    _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/random:49,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:108,
                 from permutation.cpp:1:
/usr/include/c++/10/bits/random.h:563:7: note: candidate: 'std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::operator()() [with _UIntType = long unsigned int; long unsigned int __w = 32; long unsigned int __n = 624; long unsigned int __m = 397; long unsigned int __r = 31; _UIntType __a = 2567483615; long unsigned int __u = 11; _UIntType __d = 4294967295; long unsigned int __s = 7; _UIntType __b = 2636928640; long unsigned int __t = 15; _UIntType __c = 4022730752; long unsigned int __l = 18; _UIntType __f = 1812433253; std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type = long unsigned int]'
  563 |       operator()();
      |       ^~~~~~~~
/usr/include/c++/10/bits/random.h:563:7: note:   candidate expects 0 arguments, 1 provided
stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~