답안 #685427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685427 2023-01-24T10:41:31 Z annie2018 Secret Permutation (RMI19_permutation) C++17
0 / 100
0 ms 208 KB
#include <bits/stdc++.h>
#include "permutation.h"
using namespace std;
int n;
vector <int> ans, v, a, q;
vector <bool> used;
void get (int x)
{
    used[a[x]] = 1;
    if (x == n && abs(a[1] - a[x]) == q[n])
    {
        vector <int> ret(n);
        for (int i = 1; i <= n;i++)
        {
            ret[v[i - 1] - 1] = a[i];
        }
        /*for (int i = 0; i < ret.size(); i++)
            cout << ret[i] << ' ';
        cout << "\n";*/
        answer(ret);
        exit(0);
    }
    else
    {
        int one = a[x] + q[x], two = a[x] - q[x];
        if (one > 0 && one <= n && !used[one])
        {
            a[x + 1] = one;
            get(x + 1);
        }
        else if (two > 0 && two <= n && !used[two])
        {
            a[x + 1] = two;
            get(x + 1);
        }
    }
    used[a[x]] = 0;
    a[x] = 0;
}
void solve(int nn)
{
    n = nn;
    srand(chrono::steady_clock::now().time_since_epoch().count());
    for (int i = 1; i <= n; i++)
        v.push_back(i);
    random_shuffle(v.begin(), v.end());
    //vector <int> q(n);
    q.resize(n);
    for(int i = 0; i < n; i++)
    {
        q[i] = query(v);
        rotate(v.begin(), v.begin() + 1, v.end());
    }
    rotate(v.begin(), v.begin() + 1, v.end());
    int sum = 0;
    for(int i = 0; i < n; i++)
        sum += q[i];
    sum /= (n - 1);
    for(int i = 0; i < n; i++)
        q[i] = (sum - q[i]);
    rotate(q.begin(), q.begin() + 1, q.end());
    q.insert(q.begin(), 0);
    //get(q, n);
    for (int i = 1; i <= n; i++)
    {
        a.assign(n + 1, 0);
        a[1] = i;
        used.assign(n + 1, 0);
        get(1);
    }
    //answer(ans);
}

Compilation message

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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -