제출 #703516

#제출 시각아이디문제언어결과실행 시간메모리
703516khanhhdz191Permutation (APIO22_perm)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include <perm.h>

using namespace std;
#define ll int
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
/// ko dc giai nhat chat me tay di
/// khanhdzvcl

const ll inf=2e18;
ll C(vector<ll> v)
{
    ll m=(ll)v.size();
    vector<ll> f(m);
    ll sum=1;
    for (ll i=0; i<m; i++)
    {
        f[i]=1;
        for (ll j=0; j<i; j++)
        {
            if (v[j]<v[i]) 
                f[i]+=f[j];
            f[i]=min(f[i],inf);
        }
        sum+=f[i];
        sum=min(sum,inf);
    }
    return sum;
}

vector<ll> construct_permutation(ll k)
{
    if (k==1) 
        return {};
    if (k==2) 
        return {0};
    if (k==3) 
        return {1,0};
    // if (k==4)
        // return {0,1};
    auto ans=construct_permutation(k/(4*1ll));
    ll n=(ll)ans.size();
    if (k%4==0)
    {
        ans.pb(n);
      //  ans.pb(0);
        ans.pb(n+1);
      //  for (auto &p:ans) p++;
        return ans;
    }
    if (k%4==1)
    {
        ans.pb(n);
        ans.pb(n+1);
        ans.pb(-1);
        for (auto &p:ans) p++;
        return ans;
    }
    if (k%4==2)
    {
        ans.pb(n);
        ans.pb(-1);
        ans.pb(n+1);
        for (auto &p:ans) p++;
        return ans;
    }
    auto man=ans;
    ans.pb(n);
    ans.pb(n+1);
    for (ll i=0; i<(ll)ans.size(); i++)
    {
        if (ans[i]>1) 
            ans[i]++;
    }
    ans.pb(2);
    if (C(ans)==k)
        return ans;
    for (auto &p:man) p+=2;
    man.pb(n+2);
    man.pb(1);
    man.pb(n+3);
    man.pb(0);
    return man;
}



























void tc()
{
    ll k;
    cin>> k;
    auto v=construct_permutation(k);
    for (auto &p:v) 
        cout<< p<<' ';
}

int main()
{
   // freopen("bi.txt","r",stdin); 
   // freopen("out.txt","w",stdout);
   
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
     ll t=1;
   cin>> t;
    while (t--) 
    {
        tc();
        cout<< endl;
    }

}

컴파일 시 표준 에러 (stderr) 메시지

perm.cpp:14:14: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
   14 | const ll inf=2e18;
      |              ^~~~
/usr/bin/ld: /tmp/cc1apjnw.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwQYYsv.o:perm.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccwQYYsv.o: in function `construct_permutation(int)':
perm.cpp:(.text+0x16d): undefined reference to `construct_permutation(long long)'
/usr/bin/ld: /tmp/cc1apjnw.o: in function `main':
grader.cpp:(.text.startup+0x240): undefined reference to `construct_permutation(long long)'
collect2: error: ld returned 1 exit status