QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405605#7301. Even Three is OddxuqinTL 0ms0kbC++142.6kb2024-05-06 10:26:092024-05-06 10:26:09

Judging History

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

  • [2024-05-06 10:26:09]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-06 10:26:09]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cassert>
#include<set>
#include<random>
#include<chrono>
#include<bitset>
#include<map>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#define eb emplace_back

using namespace std;
const int maxn=2000+10, maxm=500000+10, inf=2e9+10, P=1e9+7;
const double eps=1e-10, pi=acos(-1.0);
typedef long long LL;
typedef unsigned long long ULL;
const LL INF=4e18;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
inline int read() {
	int x=0, f=1; char c=getchar();
	for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=0;
	for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
	return f?x:-x;
}
mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());
inline int ksm(int x, int y) {
	int s=1;
	for(; y; y>>=1, x=1LL*x*x%P)
		if(y&1) s=1LL*s*x%P;
	return s;
}
inline int add(int x, int y) {x+=y; return x>=P?x-P:x;}
inline int del(int x, int y) {x-=y; return x<0?x+P:x;}
LL gcd(LL x, LL y) {return y?gcd(y, x%y):x;}

int f[maxn][3][maxn], tag[3][maxn];
int pw[maxn][3], ad[maxn], w[maxn];
int main() {
	int n;
	while(n=read()) {
		for(int i=1; i<=n; ++i) w[i]=read();
		for(int i=0; i<=n; ++i) {
			pw[i][0]=1;
			for(int j=1; j<=n; ++j) pw[i][j]=1LL*pw[i][j-1]*i%P;
		}
		int k=2;
		for(int i=1; i<=n; ++i)
			for(int j=0; j<=k; ++j)
				for(int v=1; v<=n; ++v) f[i][j][v]=0;
		tag[0][1]=1;
		for(int i=1; i<=n-k; ++i) {
			for(int v=1; v<=n; ++v)
				for(int j=0; j<=k; ++j) tag[j][v]=add(tag[j][v], tag[j][v-1]);
			for(int v=1; v<=n; ++v)
				for(int j=1; j<=k; ++j) tag[j][v]=add(tag[j][v], tag[j-1][v]);
			for(int v=1; v<=n; ++v) 
				for(int j=0; j<=k; ++j)
					f[i][j][v]=add(f[i][j][v], 1LL*tag[j][v]*w[v]%P*pw[v-1][j]%P);	
			for(int v=1; v<=n; ++v)
				for(int j=0; j<=k; ++j) tag[j][v]=0;	
			if(i==n-k) break;
			for(int v=1; v<=n; ++v) ad[v]=0;
			for(int j=0; j<=k; ++j)
				for(int v=1; v<=n; ++v) {
					if(j==0) {
						tag[0][1]=add(tag[0][1], f[i][j][v]);
						tag[0][v+1]=del(tag[0][v+1], f[i][j][v]);
						ad[v+1]=add(ad[1], 1LL*f[i][j][v]*pw[v][k]%P);
					} else {
						f[i+1][j-1][v]=add(f[i+1][j-1][v], f[i][j][v]);
						ad[v+1]=add(ad[v+1], 1LL*f[i][j][v]*pw[v][k-j]%P);
					}
				}
			for(int v=1; v<=n; ++v) 
				ad[v]=add(ad[v], ad[v-1]), f[i+1][k][v]=add(f[i+1][k][v], 1LL*ad[v]*w[v]%P);
		}
		int ans=0;
		for(int j=0; j<=k; ++j)
			for(int v=1; v<=n; ++v)
				ans=add(ans, 1LL*f[n-2][j][v]*pw[v][k-j]%P);
		printf("%d\n", ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
1 2 3
4
1 1 1 1

output:


result: