Submission #722285

#TimeUsernameProblemLanguageResultExecution timeMemory
722285tvladm2009Secret Permutation (RMI19_permutation)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "permutationc.h" using namespace std; typedef long long ll; mt19937 rnd(time(0)); 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); } 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 (stderr)

permutation.cpp:11:11: error: 'N_MAX' was not declared in this scope; did you mean 'NL_NMAX'?
   11 | bool used[N_MAX + 2];
      |           ^~~~~
      |           NL_NMAX
permutation.cpp: In function 'void dfs(int, int)':
permutation.cpp:23:36: error: 'used' was not declared in this scope
   23 |     if (1 <= next && next <= N && !used[next]) {
      |                                    ^~~~
permutation.cpp:34:36: error: 'used' was not declared in this scope
   34 |     if (1 <= next && next <= N && !used[next]) {
      |                                    ^~~~
permutation.cpp: In function 'void solve(int)':
permutation.cpp:56:35: error: cannot convert 'std::vector<int>' to 'int*'
   56 |         questions.push_back(query(V));
      |                                   ^
      |                                   |
      |                                   std::vector<int>
In file included from permutation.cpp:2:
permutationc.h:2:15: note:   initializing argument 1 of 'int query(int*)'
    2 | int query(int v[]);
      |           ~~~~^~~
permutation.cpp:68:13: error: 'used' was not declared in this scope
   68 |             used[j] = 0;
      |             ^~~~
permutation.cpp:72:9: error: 'used' was not declared in this scope
   72 |         used[i] = 1;
      |         ^~~~
permutation.cpp:80:20: error: cannot convert 'std::vector<int>' to 'int*'
   80 |             answer(ret);
      |                    ^~~
      |                    |
      |                    std::vector<int>
In file included from permutation.cpp:2:
permutationc.h:3:17: note:   initializing argument 1 of 'void answer(int*)'
    3 | void answer(int v[]);
      |             ~~~~^~~
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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~