# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
718576 |
2023-04-04T10:56:24 Z |
lam |
순열 (APIO22_perm) |
C++17 |
|
2 ms |
340 KB |
#include "perm.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void add(vector <int> &ans, vector <int> tmp)
{
vector <int> tmp2;
for (int i:tmp) if (i>0) tmp2.push_back(i);
sort(tmp2.begin(),tmp2.end());
for (int i:tmp2)
for (int &j:ans) if (j>=i) j++;
int bound = ans.size() + tmp.size();
for (int i:tmp) if (i<=0) ans.push_back(bound+i);
else ans.push_back(i);
}
vector<int> construct_permutation(long long k)
{
vector <int> res;
if (k==1) return res;
if (k==2) return vector <int>({0});
if (k==3) return vector <int>({1,0});
vector <int> digits;
while (k>0)
{
digits.push_back(int(k&1));
k>>=1;
}
reverse(digits.begin(),digits.end());
int it=1;
if (digits[1]==0)
{
if (digits[2]==0) res=vector<int>({3,2,1});
else res=vector <int>({2,3,1});
it+=2;
}
else
{
res=vector<int>({2,1});
it++;
}
while (it+1<digits.size())
if (digits[it]==0)
{
add(res,{0});
it++;
}
else
{
if (digits[it+1]==0) add(res,{-1,1,0});
else add(res,{-1,0,3});
it+=2;
}
if (it<digits.size())
{
if (digits[it]==0) add(res,{0});
else add(res,{0,1});
}
for (int &i:res) i--;
return res;
}
Compilation message
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | while (it+1<digits.size())
| ~~~~^~~~~~~~~~~~~~
perm.cpp:55:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | if (it<digits.size())
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |