Submission #331740

# Submission time Handle Problem Language Result Execution time Memory
331740 2020-11-29T19:59:11 Z Sho10 Secret Permutation (RMI19_permutation) C++14
53.1429 / 100
44 ms 384 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()]+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+s2);
        }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=1;
                    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 Partially correct 1 ms 364 KB Partially correct
2 Partially correct 1 ms 364 KB Partially correct
3 Partially correct 1 ms 364 KB Partially correct
4 Partially correct 1 ms 364 KB Partially correct
5 Partially correct 1 ms 364 KB Partially correct
6 Partially correct 1 ms 364 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 364 KB Partially correct
2 Partially correct 1 ms 364 KB Partially correct
3 Partially correct 1 ms 364 KB Partially correct
4 Partially correct 1 ms 364 KB Partially correct
5 Partially correct 1 ms 364 KB Partially correct
6 Partially correct 1 ms 364 KB Partially correct
7 Partially correct 3 ms 364 KB Partially correct
8 Partially correct 4 ms 364 KB Partially correct
9 Partially correct 3 ms 364 KB Partially correct
10 Partially correct 3 ms 364 KB Partially correct
11 Partially correct 3 ms 364 KB Partially correct
12 Partially correct 4 ms 364 KB Partially correct
13 Partially correct 3 ms 364 KB Partially correct
14 Partially correct 3 ms 364 KB Partially correct
15 Partially correct 4 ms 364 KB Partially correct
16 Partially correct 4 ms 364 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 364 KB Partially correct
2 Partially correct 1 ms 364 KB Partially correct
3 Partially correct 1 ms 364 KB Partially correct
4 Partially correct 1 ms 364 KB Partially correct
5 Partially correct 1 ms 364 KB Partially correct
6 Partially correct 1 ms 364 KB Partially correct
7 Partially correct 3 ms 364 KB Partially correct
8 Partially correct 4 ms 364 KB Partially correct
9 Partially correct 3 ms 364 KB Partially correct
10 Partially correct 3 ms 364 KB Partially correct
11 Partially correct 3 ms 364 KB Partially correct
12 Partially correct 4 ms 364 KB Partially correct
13 Partially correct 3 ms 364 KB Partially correct
14 Partially correct 3 ms 364 KB Partially correct
15 Partially correct 4 ms 364 KB Partially correct
16 Partially correct 4 ms 364 KB Partially correct
17 Partially correct 44 ms 364 KB Partially correct
18 Partially correct 34 ms 384 KB Partially correct
19 Partially correct 34 ms 364 KB Partially correct
20 Partially correct 37 ms 364 KB Partially correct
21 Partially correct 43 ms 364 KB Partially correct
22 Partially correct 41 ms 364 KB Partially correct
23 Partially correct 36 ms 364 KB Partially correct
24 Partially correct 38 ms 364 KB Partially correct
25 Partially correct 39 ms 364 KB Partially correct
26 Partially correct 40 ms 364 KB Partially correct