結果
| 問題 |
No.1311 Reverse Permutation Index
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2020-12-08 19:14:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,500 ms |
| コード長 | 1,009 bytes |
| コンパイル時間 | 1,769 ms |
| コンパイル使用メモリ | 171,772 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-17 20:13:12 |
| 合計ジャッジ時間 | 2,148 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=1e18;
int main(){
ll n, s; cin >> n >> s;
VI fact(s+1);
fact[0]=1;
for(int i=1;i<=s;i++)
fact[i]=fact[i-1]*i;
VI a(s);
vector<bool> f(s,0);
for(int i=s-1;i>=0;i--){
int k=n/fact[i];
REP(j,s){
if(!f[j]){
if(k==0){
f[j]=1;
a[s-1-i]=j;
break;
}
k--;
}
}
n%=fact[i];
}
VI b(s);
REP(i,s)
b[a[i]]=i;
ll ans=0;
f=vector<bool>(s,0);
REP(i,s){
ll c=0;
REP(j,b[i]){
if(!f[j])
c++;
}
f[b[i]]=1;
ans+=fact[s-1-i]*c;
}
cout << ans << endl;
return 0;
}
Haa