Submission #331737

# Submission time Handle Problem Language Result Execution time Memory
331737 2020-11-29T19:51:10 Z Sho10 Secret Permutation (RMI19_permutation) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#include "permutation.h"
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll a[300],b[300],nr[300],n;
ll calc(ll pos,ll l,ll r){
vector<int>v;
v.pb(l);
v.pb(r);
v.pb(pos);
for(ll i=1;i<=n;i++)
{
    if(i!=l&&i!=r&&i!=pos){
        v.pb(i);
    }
}
ll x=query(v);
v.clear();
v.pb(r);
v.pb(l);
v.pb(pos);
for(ll i=1;i<=n;i++)
{
    if(i!=l&&i!=r&&i!=pos){
        v.pb(i);
    }
}
ll y=query(v);
return x-y;
}
void solve(int N){
n=N;
for(ll i=1;i+2<=n;i++)
{
    a[i]=calc(i,i+1,i+2);
}
for(ll i=2;i<n;i++)
    b[i]=calc(i,i-1,i+1);
vector<int>ans;
for(ll i=1;i<=n;i++)
{
    for(ll j=1;j<=n;j++)
    {
        if(i==j){
            continue;
        }
        ans.clear();
        ans.pb(i);
        ans.pb(j);
        ll check=0;
        while(ans.size()<n){
            ll s1,s2,s3;
            s1=abs(ans.back()-ans[ans.size()-2]);
            s2=abs(a[ans.size()-1]+s1);
            s3=abs(b[ans.size()-1]+s1);
            ll x,y;
            x=ans[ans.size()-2];
            y=ans.back();
            if(s2==s3+s1){
                if(x>y){
                    ans.pb(x-s2);
                }else ans.pb(x+s2);
            }else if(s3==s1+s2){
            if(x>y){
                ans.pb(x+s2);
            }else ans.pb(x-s2);
        }else if(s1==s2+s3){
        if(x>y){
            ans.pb(x-s2);
        }else ans.pb(x+2);
        }else {
        check=1;
        break;
        }
        }
        for(auto it : ans){
            if(it<1||it>n){
                check=1;
            }
        }
        if(check==0){
            memset(nr,0,sizeof(nr));
            for(auto it : ans){
                if(nr[it]){
                    check=0;
                    break;
                }
                nr[it]=1;
            }
        }
        if(check==0){
            answer(ans);
            return;
        }
    }
}
answer(ans);
}
        /*
int32_t main(){
CODE_START;
*/

Compilation message

permutation.cpp: In function 'void solve(int)':
permutation.cpp:68:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   68 |         while(ans.size()<n){
      |               ~~~~~~~~~~^~
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 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -