結果

問題 No.696 square1001 and Permutation 5
ユーザー beetbeet
提出日時 2018-06-08 23:54:29
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 783 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 74,732 KB
実行使用メモリ 89,040 KB
最終ジャッジ日時 2023-09-13 00:30:59
合計ジャッジ時間 24,645 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
    int n;
    int[] bit;
    int sum(int i){
	int s=bit[0];
	for(int x=i;x>0;x-=(x&-x))
	    s+=bit[x];
	return s;
    }
    void add(int i,int a){
	if(i==0) return;
	for(int x=i;x<=n;x+=(x&-x))
	    bit[x]+=a;
    }

    void run(){
	Scanner cin = new Scanner(System.in);
	n = cin.nextInt();
	int[] p = new int[n];
	for(int i=0;i<n;i++) p[i]=cin.nextInt();    
	
	bit = new int[n+100];
	
	BigDecimal ans = BigDecimal.ONE, x = BigDecimal.ONE;
	for(int i=1;i<=n;i++){
	    ans = ans.add(x.multiply(new BigDecimal(sum(p[n-i]))));
	    add(p[n-i], 1);
	    x = x.multiply(new BigDecimal(i));
	}
	System.out.println(ans);
    }
    
    public static void main(String[] args) {
	new Main().run();
    }
}
0