結果

問題 No.3271 PQ Dot Product
ユーザー rabimea
提出日時 2025-09-23 21:57:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 76 ms / 1,000 ms
コード長 1,484 bytes
コンパイル時間 3,054 ms
コンパイル使用メモリ 286,380 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-23 21:57:45
合計ジャッジ時間 9,579 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>

using std::cin, std::cout, std::cerr;
using ll = long long;

int main() {
    std::ios::sync_with_stdio(false);
    ll n; ll m; cin >> n >> m;
    std::vector<int> q;
    ll orig_n = n;
    int shift = 0;
    while(n > 10) {
        n --;
        ll min = ll(n) * (n + 1) * (n + 2) / 6;
        ll max = ll(n) * (n + 1) * (2 * n + 1) / 6;
        ll x = ll(n) * (n + 1) / 2 + n + 1;
        ll y = ll(n + 1) * (n + 1);
        // cout << n << ' ' << m << ' ' << min << ' ' << max << ' ' << x << ' ' << y << '\n';
        if(max + x >= m) {
            m -= x;
            shift ++;
            q.push_back(shift);
        } else {
            m -= y;
            q.push_back(n + 1 + shift);
        }
    }
    
    bool done = false;
    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 1);
    do {
        int ans = 0;
        for(int i = 0; i < n; i ++) {
            ans += (i + 1) * p[i];
        }
        if(ans == m) {
            done = true;
            break;
        }
    }while(std::next_permutation(p.begin(), p.end()));
    if(!done) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for(int &x : p) x += shift;
        p.insert(p.end(), q.rbegin(), q.rend());
        for(int i = 1; i <= orig_n; i ++) cout << i << ' '; cout << '\n';
        for(int x : p) cout << x << ' '; cout << '\n';
    }
}
0