Submission #443724

# Submission time Handle Problem Language Result Execution time Memory
443724 2021-07-11T18:44:42 Z valerikk Secret Permutation (RMI19_permutation) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#ifdef EVAL
#include "permutation.h"
#endif

typedef long long ll;
using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

#ifndef EVAL
int N;
int P[256 + 10];
#endif

int query_(vector<int> v) {
#ifdef EVAL
    for (int &i : v) {
        i++;
    }
    return query(v);
#else
    int sum = 0;
    for (int i = 1; i < v.size(); i++)
        sum += abs(P[v[i]] - P[v[i - 1]]);
    return sum;
#endif
}

void answer_(vector<int> p) {
    for (int &i : p) {
        i++;
    }
#ifdef EVAL
    answer(p);
#else
    for (int i = 0; i < p.size(); i++)
        cout << p[i] << " ";
    exit(0);
#endif
}

void solve(int n) {
    if (n <= 10) {
        vector<int> p(n);
        iota(p.begin(), p.end(), 0);
        shuffle(p.begin(), p.end());
        vector<int> d(n);
        for (int i = 0; i < n; i++) {
            d[p[n - 1]] = query_(p);
            rotate(p.begin(), p.begin() + 1, p.end());
        }
        int sum = 0;
        for (int i = 0; i < n; i++)
            sum += d[i];
        sum /= n - 1;
        for (int i = 0; i < n; i++)
            d[i] = sum - d[i];
        do {
            bool ok = true;
            for (int i = 0; i < n; i++)
                ok &= d[i] == abs(p[i] - p[(i + 1) % n]);
            if (ok)
                answer_(p);
        } while (next_permutation(p.begin(), p.end()));
    }
}

#ifndef EVAL
int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    solve(N);
}
#endif

Compilation message

permutation.cpp: In function 'void solve(int)':
permutation.cpp:47:35: error: no matching function for call to 'shuffle(std::vector<int>::iterator, std::vector<int>::iterator)'
   47 |         shuffle(p.begin(), p.end());
      |                                   ^
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:3748:5: note: candidate: 'template<class _RAIter, class _UGenerator> void std::shuffle(_RAIter, _RAIter, _UGenerator&&)'
 3748 |     shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~~~~
/usr/include/c++/10/bits/stl_algo.h:3748:5: note:   template argument deduction/substitution failed:
permutation.cpp:47:35: note:   candidate expects 3 arguments, 2 provided
   47 |         shuffle(p.begin(), p.end());
      |                                   ^
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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~