QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405606#7301. Even Three is OddxuqinWA 2ms4120kbC++142.6kb2024-05-06 10:26:352024-05-06 10:26:36

Judging History

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

  • [2024-05-06 10:26:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4120kb
  • [2024-05-06 10:26:35]
  • 提交

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(scanf("%d", &n)==1) {
		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: 100
Accepted
time: 0ms
memory: 3980kb

input:

3
1 2 3
4
1 1 1 1

output:

72
256

result:

ok 2 number(s): "72 256"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 4120kb

input:

20
2 1 1 2 1 1 2 2 1 1 1 2 1 2 2 2 2 2 1 1
20
1 1 1 1 1 1 1 2 2 2 2 1 2 1 2 1 1 1 2 2
20
2 1 2 2 1 2 2 1 1 1 2 1 2 1 2 2 1 1 2 1
20
1 1 1 1 1 2 1 1 1 2 1 2 2 1 1 2 2 2 1 2
20
2 2 1 1 2 2 2 1 2 2 1 2 2 2 2 1 2 2 2 2
20
1 1 2 1 2 1 2 2 1 2 2 2 1 2 1 2 2 2 1 1
20
1 2 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 2 2 1...

output:

844741366
101770755
313325704
432470057
588132789
229848239
727748166
653081888
113652164
287548544
903082272
804387442
923108440
998663907
631096916
670463041
688306930
232862505
9084663
924263342
573170703
476382301
843070996
593259280
390928316
768376176
496591930
502615997
418357915
700231451
53...

result:

wrong answer 1st numbers differ - expected: '319733964', found: '844741366'