Submission #931902

# Submission time Handle Problem Language Result Execution time Memory
931902 2024-02-22T14:22:34 Z djs100201 Permutation (APIO22_perm) C++17
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
#include<perm.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<ll, P>;
const ll n_ =4e5+100, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353;
ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k;
ll gcd(ll x,ll y){
	if(!y)return x;
	return gcd(y,x%y);
}
vector<int> construct_permutation(long long k){
    vector<int>res,A;
    x=k-1;
    while(x){
        a=x%4; 
        if(x==2){
            res.push_back(1);
            res.push_back(0);
            break;
        }
        else if(x==1){
            res.push_back(0);
            break;
        }
        else if(x==4){
            res.push_back(1);
            res.push_back(2);
            res.push_back(0);
          	break;
        }
        else if(x==3){
            res.push_back(0);
            res.push_back(1);
            break;
        }
        if(a==0){
            A.push_back(-1);
            A.push_back(1);
            A.push_back(1);
            x=(x-4)/4;
        }
        else if(a==1){
            A.push_back(1);
            A.push_back(2);    
            x=(x-1)/4-1;
        }
        else if(a==2){
            A.push_back(3);
            x=x-3;
            //A.push_back(2);
            //A.push_back(2);
            //x=(x-2)/4-1;
        }
        else if(a==3){
            A.push_back(1);
            A.push_back(1);
            x=(x-3)/4;
        }
    }
    reverse(all(A));
    for(auto nxt:A){
        if(nxt==1){
            res.push_back(res.size());
        }
        else if(nxt==-1){
            for(auto &i:res)i++;
            res.push_back(0);
        }
        else if(nxt==2){
            for(auto &i:res)i++;
            res.push_back(res.size()+1);
            res.push_back(0);
        }
        else{
            assert(res.size()>=2);
            ll idx=0;
            for(int j=1;j<res.size();j++){
                if(res[j]<res[0]){
                    idx=j;
                    break;
                }
            }
            vector<int>T;
            for(auto &i:res){
                if(i>res[0])i++;
            }
            for(int i=0;i<=idx;i++)T.push_back(res[i]);
            T.push_back(res[0]+1);
            for(int i=idx+1;i<res.size();i++)T.push_back(res[i]);
            res=T;
        }
    }
    return res;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:84:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             for(int j=1;j<res.size();j++){
      |                         ~^~~~~~~~~~~
perm.cpp:96:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |             for(int i=idx+1;i<res.size();i++)T.push_back(res[i]);
      |                             ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -