結果

問題 No.1867 Partitions and Inversions
ユーザー Shuai ZuiShuai Zui
提出日時 2023-12-26 21:33:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,789 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 177,404 KB
実行使用メモリ 129,272 KB
最終ジャッジ日時 2023-12-26 21:34:21
合計ジャッジ時間 25,973 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,748 KB
testcase_01 AC 3 ms
7,748 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 3 ms
7,748 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 688 ms
129,272 KB
testcase_64 AC 3 ms
7,748 KB
testcase_65 AC 3 ms
7,748 KB
testcase_66 WA -
testcase_67 AC 763 ms
129,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define uint unsigned long long
#define il inline
#define ct const
#define dl double
#define pk push_back
#define fi first
#define N 3010
#define se second
#define pii pair<int,int>
#define inf (int)(1000000000000000000)
using namespace std;
#define lowbit(x) (x&-x)
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
il int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);ch=getchar();
	}
	return x*f;
}
char f__[40];
il void write(int x){
	int cnt=0;
	if(x<0){
		putchar('-');x=-x;
	}
	if(!x) putchar('0');
	while(x){
		f__[cnt++]=x%10+'0';x/=10;
	}
	while(cnt) putchar(f__[--cnt]);
}
int n,p[N],sum[N][N],f[N],g[N],s[N][N];
il void solve(int l,int r,int L,int R){
	if(l>r) return;
	int mid=(l+r)>>1,p=0;
	for(int i=L;i<=min(mid-1,R);++i){
		int tmp=f[i]+s[i][mid];
		if(tmp<g[mid]){
			g[mid]=tmp;p=i;
		}
	}
	// cerr<<l<<" "<<r<<" "<<L<<" "<<R<<"\n";
	// cerr<<g[mid]<<" "<<p<<"\n";
	solve(l,mid-1,L,p);solve(mid+1,r,p,R);
}
signed main(){
    // freopen("1.in","r",stdin);
    // freopen("1.out","w",stdout);
	n=read();
	for(int i=1;i<=n;++i) p[i]=read();
	for(int i=1;i<=n;++i){
		for(int j=1;j<=i;++j) ++sum[i][p[j]];
		for(int j=1;j<=n;++j) sum[i][j]+=sum[i][j-1];
	}
	for(int i=0;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			s[i][j]=s[i][j-1]+sum[i][n]-sum[i][p[j]];
		}
	}
	// cerr<<s[4][5]<<" ";
	// cerr<<calc(1,4,3)<<" ";
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	for(int j=1;j<=n;++j){
		memset(g,0x3f,sizeof(g));
		solve(1,n,0,n-1);
		memcpy(f,g,sizeof(f));
		write(f[n]);putchar('\n');
		// for(int i=0;i<=n;++i) cerr<<f[i]<<" ";
		// cerr<<"\n";
	}
	return 0;
}
0