結果
| 問題 | No.3271 PQ Dot Product |
| コンテスト | |
| ユーザー |
C
|
| 提出日時 | 2026-10-22 00:15:28 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 18 ms / 1,000 ms |
| + 718µs | |
| コード長 | 1,666 bytes |
| 記録 | |
| コンパイル時間 | 6,052 ms |
| コンパイル使用メモリ | 389,576 KB |
| 実行使用メモリ | 9,908 KB |
| 最終ジャッジ日時 | 2026-10-22 00:16:01 |
| 合計ジャッジ時間 | 11,315 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#include <boost/polygon/point_data.hpp>
#include <boost/polygon/voronoi.hpp>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pll=pair<ll,ll>;
using pi=pair<int,int>;
// using mint=modint998244353;
// using mint2=static_modint<2>;
// using BoostPoint=boost::polygon::point_data<int>;
// using Voronoi=boost::polygon::voronoi_diagram<double>;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,K;
cin>>N>>K;
ll L=N*(N+1)*(N+2)/6,U=N*(N+1)*(2*N+1)/6;
if(K<L||K>U){
cout<<"No\n";
return 0;
}
vll Q(N);
bool ok=false;
if(N<4){
//全探索
iota(all(Q),1);
do{
ll inner=0;
rep(i,1,N+1)inner+=i*Q[i-1];
if(inner==K){
ok=true;
break;
}
}while(next_permutation(all(Q)));
}else{
//確実にできる
ll l=0,r=N-1;
for(ll n=N;n>4;--n){
ll prevU=n*(n-1)*(2*n-1)/6,add=n*(n+1)/2;
if(K<=prevU+add){
Q[l]=n;
l++;
K-=add;
}else{
Q[r]=n;
r--;
K-=n*n;
}
}
vll v={1,2,3,4};
do{
ll inner=v[0]+2*v[1]+3*v[2]+4*v[3];
if(inner==K){
ok=true;
Q[l]=v[0],Q[l+1]=v[1],Q[l+2]=v[2],Q[l+3]=v[3];
break;
}
}while(next_permutation(all(v)));
}
if(ok){
cout<<"Yes\n";
rep(i,0,N){
if(i)cout<<' ';
cout<<i+1;
}
cout<<'\n';
rep(i,0,N){
if(i)cout<<' ';
cout<<Q[i];
}
cout<<'\n';
}else{
cout<<"No\n";
}
}
C