제출 #737378

#제출 시각아이디문제언어결과실행 시간메모리
737378becaido순열 (APIO22_perm)C++17
100 / 100
2 ms340 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "perm.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second vector<int> construct_permutation(ll k) { vector<int> ans; vector<pair<int, int>> p; int m = __lg(k); FOR (i, 0, m - 1) p.pb(2 * i, 10000 + i); k -= 1ll << m; int cnt = 0, mn = 100, smn = 100; for (int i = m; i >= 0; i--) if (k >> i & 1) { if (i > 0 && k >> (i - 1) & 1 && cnt >= 2) { p.pb(2 * (m - i) + 1, smn + i); i--; } else { p.pb(2 * (m - i) - 1, 100 * i); smn = mn, mn = 100 * i; cnt++; } } vector<int> lis; for (auto [pos, val] : p) lis.pb(val); sort(lis.begin(), lis.end()); sort(p.begin(), p.end()); for (auto [pos, val] : p) ans.pb(lower_bound(lis.begin(), lis.end(), val) - lis.begin()); return ans; } #ifdef WAIMAI static long long MX=1e18; static bool check_permutation(vector<int> v) { sort(v.begin(),v.end()); for(int i=0;i<v.size();i++) if(v[i]!=i) return 0; return 1; } long long count_increasing(const vector<int>& v) { vector<long long> dp(v.size() + 1, 0); dp[0] = 1; for (int x : v) { for (int i = 0; i <= x; i++) { dp[x+1] += dp[i]; dp[x+1] = min(dp[x+1],MX+1); } } long long result = 0; for (int i = 0; i <= (int)v.size(); i++){ result += dp[i]; result = min(result,MX+1); } return result; } int main() { int t; assert(1 == scanf("%d", &t)); while(t--) { long long k; assert(1 == scanf("%lld",&k)); vector<int> ret=construct_permutation(k); if(!check_permutation(ret)) { printf("WA: Returned array is not a permutation\n"); exit(0); } long long inc=count_increasing(ret); if(inc!=k) { if(inc==MX+1) printf("WA: Expected %lld increasing subsequences, found more than %lld\n",k, MX); else printf("WA: Expected %lld increasing subsequences, found %lld\n",k,inc); exit(0); } printf("%d\n",(int)ret.size()); for(int i=0;i<ret.size();i++) { printf("%d",ret[i]); if(i+1==ret.size()) printf("\n"); else printf(" "); } } return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...