답안 #584006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584006 2022-06-26T16:22:17 Z YassineBenYounes 순열 (APIO22_perm) C++17
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
ll modd(ll x, ll n){while(x < 0){x += n;}return (x % n);} // modulo for negative numbers
#define endl "\n"
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd  pair<double,double>
#define vdd  vector<pdd>
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int msb(ll n){
    int i = 0;
    int last = 0;
    while(n > 0){
        if(n&1)last = i;
        n/=2;
        i++;
    }
    return last;
}

vector<int> construct_permutation(long long k){
     int i = 0;
     vi res;
     while(k > 0){
        ll wanted = k;
        if(i != 0)wanted++;
        int found = msb(wanted);
        res.pb(found);
        k -= (1 << found);
        if(i !=0)k++;
        i++;
     }
     int c = 0;
     for(int i = 0; i < res.size();i++){
        c += res[i];
     }
     vi v;
     if(c == 1)return v;
     for(int i = 0; i < res.size();i++){
        int x = c - res[i];
        for(int j = x; j< c;j++){
            v.pb(j);
        }
        c = x;
     }
     return v;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |      for(int i = 0; i < res.size();i++){
      |                     ~~^~~~~~~~~~~~
perm.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |      for(int i = 0; i < res.size();i++){
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Integer 0 violates the range [1, 5000]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Integer 0 violates the range [1, 5000]
3 Halted 0 ms 0 KB -