Submission #685460

# Submission time Handle Problem Language Result Execution time Memory
685460 2023-01-24T11:59:20 Z dranaya_dusha Secret Permutation (RMI19_permutation) C++17
0 / 100
1 ms 336 KB
//#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
////#define int long long
//#define mp make_pair
//#define pb push_back
//#define fi first
//#define se second
//#define pii pair <int, int>


#include "permutation.h"
using namespace std;
vector<int> ans(300), q(300), v;
int n;
vector<int> used;
bool check (int p)
{
    used[ans[p]]=1;
    if (p==n && abs(ans[p] - ans[1] ) == q[n])
    {
        vector<int> tut(n);
        for (int i=1; i<=n; i++)
            tut[v[i-1]-1]=ans[i];
        answer(tut);
        exit(0);
    }
    else
    {
        if (ans[p]+q[p]<=n && ans[p]+q[p] > 0 && !used[ans[p]+q[p]])
        {
            ans[p+1]=ans[p]+q[p];
            // used[ans[v[p]-1]+q[i]]=1;
            check(p+1);
        }
        if (ans[p]-q[p] > 0 && ans[p]-q[p] <= n && !used[ans[p]-q[p]])
        {
            ans[p+1]=ans[p]-q[p];
            // used[ans[v[p]-1]+q[i]]=1;
            check(p+1);
        }
        used[ans[p]]=0;
        ans[p]=0;
    }
}


void solve(int nn)
{
    n=nn;
    for (int i=1; i<=n; i++)
        v.push_back(i);
    srand(time(NULL));
    random_shuffle(v.begin(), v.end());
    for(int i=1; i<=n; i++)
    {
        rotate(v.begin(),v.begin()+1,v.end());
        q[i] = query(v);
    }
//    for (int i=0; i<n; i++)
//        cout << q[i] << ' ';
    rotate(v.begin(),v.begin()+1,v.end());
    int sum=0;
    for(int i=1; i<=n; i++)
    {
        sum+=q[i];
    }
    sum/=(n-1);
    for(int i=1; i<=n; i++) q[i]=(sum-q[i]);

    q[n+1]=q[1];
    for(int i=1; i<=n; i++) 
        q[i]=q[i+1];

    ans.assign(n+10, 0);

    for (int i=1; i<=n; i++)
    {
        used.assign(n+10, 0);
        ans.assign(n+10, 0);
        ans[1]=i;
        check(1);
    }
}

Compilation message

permutation.cpp: In function 'bool check(int)':
permutation.cpp:42:15: warning: control reaches end of non-void function [-Wreturn-type]
   42 |         ans[p]=0;
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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -