結果

問題 No.3271 PQ Dot Product
ユーザー Rubikun
提出日時 2025-09-12 22:25:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 1,000 ms
コード長 2,300 bytes
コンパイル時間 2,188 ms
コンパイル使用メモリ 211,360 KB
実行使用メモリ 23,116 KB
最終ジャッジ日時 2025-09-12 23:42:29
合計ジャッジ時間 8,307 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

map<int,vi> MA[13];
ll Z[MAX];
deque<ll> ans;

void solve(ll N,ll K,ll ad){
    if(N<=8){
        if(MA[N].count(K)){
            for(ll a:MA[N][K]) ans.pb(ad+a-1);
        }else{
            
        }
        return;
    }
    ll L=N*(N+1)*(N+2)/6,R=Z[N];
    //cout<<N<<" "<<L<<" "<<R<<endl;
    if(K<L||R<K){
        return;
    }
    if(R-K<=K-L){
        solve(N-1,K-N*N,ad+1);
        ans.push_front(ad);
    }else{
        solve(N-1,K-N*(N+1)/2,ad+1);
        ans.push_back(ad);
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    Z[0]=0;
    for(ll i=1;i<MAX;i++){
        Z[i]=Z[i-1]+i*i;
    }
    
    for(int N=1;N<=8;N++){
        vi Q(N);iota(all(Q),1);
        do{
            int sum=0;
            for(int i=0;i<N;i++){
                sum+=(i+1)*Q[i];
            }
            if(!MA[N].count(sum)) MA[N][sum]=Q;
        }while(next_permutation(all(Q)));
        /*
        cout<<N<<" "<<si(MA)<<"\n";
        for(auto [a,P]:MA){
            cout<<a<<" : ";
            for(int x:P) cout<<x<<" ";
            cout<<"\n";
        }
         */
    }
    
    
    ll N,K;cin>>N>>K;
    solve(N,K,1);
    if(si(ans)==N){
        cout<<"Yes\n";
        for(int i=0;i<N;i++){
            cout<<i+1<<" ";
        }
        cout<<"\n";
        for(int a:ans) cout<<a<<" ";
        cout<<"\n";
    }else{
        cout<<"No\n";
    }
}


0