QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#347042#7199. BombrageOfThunderWA 8ms144956kbC++142.2kb2024-03-09 10:17:012024-03-09 10:17:01

Judging History

你现在查看的是最新测评结果

  • [2024-03-09 10:17:01]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:144956kb
  • [2024-03-09 10:17:01]
  • 提交

answer

#include<bits/stdc++.h>

#define ll long long
#define mk make_pair
#define fi first
#define se second
#define Cout cerr

using namespace std;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
	for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
	return x*f;
}

const int mod=998244353;
int ksm(int x,ll y,int p=mod){
	int ans=1;y%=(p-1);
	for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
	return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
int cmod(int x){if(x>=mod)x-=mod;return x;}

template<typename T>void cmax(T &x,T v){x=max(x,v);}
template<typename T>void cmin(T &x,T v){x=min(x,v);}

const int N=3005;
int n,pos[N];
ll f[2][N][N];

const ll INF=1e15;

double Ti=0;

void clr(){
	for(int i=0;i<=n;i++)pos[i]=0;
	for(int c=0;c<=1;c++)for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)f[c][i][j]=INF;
}

void solve(){
	if(n==1)return puts("0"),void();
	pos[0]=-1e6,pos[n+1]=2e6;
	
	vector<vector<pair<int,int> > >ws(n+1);
	for(int i=1;i<=n;i++){
		vector<pair<int,int> >vals;
		for(int j=1;j<=n;j++)vals.emplace_back(mk(abs(pos[i]-pos[j]),j));
		sort(vals.begin(),vals.end());
		int l=i,r=i;
		for(auto [dis,id]:vals){
			cmin(l,id),cmax(r,id);
			ws[i].emplace_back(mk(l,r));
		}
	}
	
	auto sq=[&](int x){return 1ll*x*x;};
	
	int cur=0;
	f[cur][1][2]=sq(pos[2]-pos[1]);
	for(int i=2;i<=n;i++){
		for(int j=0;j<=n;j++)for(int k=0;k<=n;k++)f[cur^1][j][k]=INF;
//		Cout<<"ws "<<i<<" = ";for(auto [l,r]:ws[i])Cout<<"["<<l<<","<<r<<"] ";Cout<<endl;
		for(int j=1;j<=i-1;j++)for(int k=i;k<=n;k++)if(f[cur][j][k]<=INF){
//			cout<<"f "<<i-1<<" "<<j<<" "<<k<<" = "<<f[cur][j][k]<<endl;
			for(auto [l,r]:ws[i]){
				if(l==i&&r==i)continue;
				int jj=(l<=j?i:j);
				cmin(f[cur^1][jj][max(k,r)],f[cur][j][k]+sq(max(pos[r]-pos[i],pos[i]-pos[l])));
			}
		}
		cur^=1;
	}
	cout<<f[cur][n][n]<<'\n';
	
	clr();
}

signed main(void){

	memset(f,63,sizeof(f));
	while(cin>>n){
		for(int i=1;i<=n;i++)cin>>pos[i];
		solve();
	}

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 144692kb

input:

5
1 4 5 6 10
3
1 2 6

output:

51
33

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 3ms
memory: 144872kb

input:

18
1 2 3 6 11 23 47 106 235 551 1301 3159 7741 19320 48629 123867 317955 823065
5
1 5 6 7 11
2
1 1000000
3
1 12345 1000000
4
1 2 3 1000000

output:

554621353432
59
1999996000002
1951077172386
1999988000020

result:

ok 5 tokens

Test #3:

score: 0
Accepted
time: 8ms
memory: 144956kb

input:

5
1 2 5 6 7
5
1 4 5 7 10
5
1 2 5 7 10
5
1 4 5 7 10
5
1 2 5 6 7
5
1 4 5 7 10
5
1 2 5 6 7
5
1 2 5 6 7
5
2 5 6 7 9
5
2 5 6 7 9
5
1 4 5 7 10
5
2 3 5 6 9
5
2 5 6 7 9
5
1 2 5 6 7
5
2 3 6 8 9
5
1 2 5 7 10
5
2 3 5 6 9
5
1 4 5 7 10
5
1 2 5 6 7
5
1 2 5 7 10
5
2 5 6 7 9
5
1 2 5 7 10
5
1 4 5 7 10
5
2 3 6 8 9
5
...

output:

21
37
37
37
21
37
21
21
27
27
37
24
27
21
24
37
24
37
21
37
27
37
37
24
27
27
27
27
24
24
37
27
24
24
27
21
21
37
37
21
24
27
24
27
21
27
37
37
37
27
37
21
24
37
37
24
24
21
27
24
37
27
21
37
37
24
27
21
27
37
21
37
37
24
37
24
37
37
21
37
21
27
21
24
24
27
27
24
37
24
24
27
37
24
27
37
24
21
24
24

result:

ok 100 tokens

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 144808kb

input:

10
6 8 24 41 42 43 66 81 83 99
10
3 17 28 51 54 58 65 71 77 98
10
31 55 56 59 63 67 78 84 89 93
10
31 55 56 59 63 67 78 85 89 93
10
11 12 13 29 36 50 74 75 94 95
10
2 16 21 23 45 47 69 70 72 96
10
15 16 19 47 49 72 73 79 86 92
10
31 34 55 56 59 63 67 78 84 93
10
1 23 35 45 48 62 64 69 70 90
10
5 22 ...

output:

2158
2429
1392
1396
2225
2495
2233
1259
2188
2130
2027
2526
1418
1988
2188
2000
1428
2515
3627
2327
1348
2051
2158
1462
1988
2045
2083
2291
1462
2345
2333
1396
2258
2142
1428
2051
1538
2002
2363
2173
2276
2465
2118
1902
1538
2051
2069
2781
2118
2526
3579
2394
1196
2083
2033
2129
2129
2345
3579
2427
...

result:

wrong answer 12th words differ - expected: '2529', found: '2526'