Submission #685402

# Submission time Handle Problem Language Result Execution time Memory
685402 2023-01-24T10:06:04 Z dranaya_dusha Secret Permutation (RMI19_permutation) C++17
0 / 100
16 ms 208 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;

//bool check (vector<int> &q, int p, int n)
//{
//    ans.assign(n, 0);
//    vector<int> used(n+1);
//    ans[p]=1;
//    used[1]=1;
//    for (int i=p; i<n-1; i++)
//        if (ans[i]+q[i]<=n && !used[ans[i]+q[i]]){
//            ans[i+1]=ans[i]+q[i];
//            used[ans[i]+q[i]]=1;
//        }
//        else if (ans[i]-q[i]>0 && !used[ans[i]-q[i]])
//        {
//            ans[i+1]=ans[i]-q[i];
//            used[ans[i]-q[i]]=1;
//        }
//        else return false;
//    for (int i=p; i>0; i--)
//    {
//        if (ans[i] + q[i - 1] <= n && !used[ans[i] + q[i - 1]]){
//            ans[i - 1] = ans[i] + q[i - 1];
//            used[ans[i] + q[i - 1]] = 1;
//        }
//        else if (ans[i] - q[i - 1] > 0 && !used[ans[i] - q[i - 1]])
//        {
//            ans[i-1] = ans[i]-q[i - 1];
//            used[ans[i] - q[i - 1]] = 1;
//        }
//        else return false;
//    }
//    return true;
//}


void check2(vector<int>&q, vector<int> &v, int n)
{
    vector<int> v2;
    for (int i=1; i<=n; i++)
        v2.push_back(i);
    vector<int> a(n);
    for (int i=1; i<=n; i++)
        a[i-1]=i;
    do
    {
        random_shuffle(v2.begin(), v2.end());
        int res=query(v2);
        bool mark = 1;
        int res2=0;
        for (int i=0; i<n-1; i++)
            res2+=abs(a[v2[i]-1]-a[v2[i+1]-1]);
        if (res2!=res) mark=0;
        for (int i=0; i<n-1; i++)
            if (abs(a[v[i]-1]-a[v[i+1]-1])!=q[i]) mark = 0;
        if (abs(a[v[n-1]-1]-a[v[0]-1])!=q[n-1]) mark=0;
        if (mark){
            ans = a;
            return;
        }
    }while (next_permutation(a.begin(), a.end()));
}

void solve(int n) {

    vector<int> v;
    for (int i=1; i<=n; i++)
        v.push_back(i);
    srand(time(NULL));
    random_shuffle(v.begin(), v.end());
    vector<int> q(n);
    for(int i=0;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=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());
//    for (int i=0; i<n; i++)
//        cout << q[i] << ' ';
//    cout << endl;
//        for (int i=0; i<n; i++)
//        cout << v[i] << ' ';
//    cout << endl;

    ans.assign(n, 0);
    check2(q,v, n);
//    for (int i=0; i<n; i++)
//        cout << ans[i] <<' ';
    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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 16 ms 208 KB Partially correct
2 Incorrect 0 ms 208 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 16 ms 208 KB Partially correct
2 Incorrect 0 ms 208 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 16 ms 208 KB Partially correct
2 Incorrect 0 ms 208 KB Output isn't correct
3 Halted 0 ms 0 KB -