結果

問題 No.1311 Reverse Permutation Index
ユーザー kotatsugamekotatsugame
提出日時 2020-12-08 04:56:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 447 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 64,832 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 16:55:32
合計ジャッジ時間 1,291 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
long K;
int N;
long F[21];
int A[21],B[21];
main()
{
	cin>>K>>N;
	F[0]=1;
	for(int i=1;i<=N;i++)F[i]=F[i-1]*i;
	for(int i=0;i<N;i++)B[i]=-1;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)if(B[j]==-1)
		{
			if(K>=F[N-i-1])K-=F[N-i-1];
			else
			{
				A[i]=j;
				B[j]=i;
				break;
			}
		}
	}
	long ans=0;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<B[i];j++)if(A[j]>i)ans+=F[N-i-1];
	}
	cout<<ans<<endl;
}
0