Submission #722295

#TimeUsernameProblemLanguageResultExecution timeMemory
722295tvladm2009Secret Permutation (RMI19_permutation)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "permutation.h" using namespace std; typedef long long ll; const int N_MAX = 256; mt19937 gen(time(0)); uniform_int_distribution <int64_t> rng; 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(), rng); 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 (stderr)

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::uniform_int_distribution<long int>&]':
permutation.cpp:54:43:   required from here
/usr/include/c++/10/bits/stl_algo.h:4636:48: error: no match for call to '(std::uniform_int_distribution<long int>) (__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/bits/stl_algo.h:66,
                 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/uniform_int_dist.h:188:2: note: candidate: 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&) [with _UniformRandomNumberGenerator = long int; _IntType = long int; std::uniform_int_distribution<_IntType>::result_type = long int]' (near match)
  188 |  operator()(_UniformRandomNumberGenerator& __urng)
      |  ^~~~~~~~
/usr/include/c++/10/bits/uniform_int_dist.h:188:2: note:   conversion of argument 1 would be ill-formed:
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:4636:65: error: cannot bind non-const lvalue reference of type 'long int&' to an rvalue of type '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'}
 4636 |    _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
      |                                                 ~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/bits/stl_algo.h:66,
                 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/uniform_int_dist.h:193:2: note: candidate: 'template<class _UniformRandomNumberGenerator> std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&, const std::uniform_int_distribution<_IntType>::param_type&) [with _UniformRandomNumberGenerator = _UniformRandomNumberGenerator; _IntType = long int]'
  193 |  operator()(_UniformRandomNumberGenerator& __urng,
      |  ^~~~~~~~
/usr/include/c++/10/bits/uniform_int_dist.h:193:2: note:   template argument deduction/substitution failed:
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:4636:48: note:   candidate expects 2 arguments, 1 provided
 4636 |    _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~
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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~