QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226670#5408. 计数鸡xyz12320 12ms28560kbC++142.0kb2023-10-26 13:23:522023-10-26 13:23:52

Judging History

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

  • [2023-10-26 13:23:52]
  • 评测
  • 测评结果:20
  • 用时:12ms
  • 内存:28560kb
  • [2023-10-26 13:23:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
long long T,a,b,c,d[1000001],v[1000001],g[301][301],o,f[1000001],h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],st[1000001],u[1000001];
char s[1000001];
struct p{long long q,w;}l[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
int main()
{
//	freopen("1.in","r",stdin);
	srand((unsigned)(time(0)^(*new int)));
	fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
	inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	T=1;
//	scanf("%lld",&T);
	for(int ii=1;ii<=T;ii++)
	{
		scanf("%lld",&a);
		for(int i=1;i<=a;i++) scanf("%lld",&d[i]);
		for(int i=1;i<=a;i++) scanf("%lld",&f[i]);
		for(int i=1;i<=a;i++)
		{
			for(int j=1;j<=a;j++)
			{
				g[i][a-j+1]=1;
				for(int k=i+1;k<=a;k++) if(j+f[i]>=d[k]) g[i][a-j+1]*=-1;
			} 
		}
		an=1;
		for(int i=1;i<=a;i++)
		{
			long long tt=0;
			for(int j=i;j<=a;j++)
			{
				if(g[j][i])
				{
					tt=j;break;
				}
			}
			if(!tt){an=0;break;}
			if(tt!=i) an=-an;
			for(int j=1;j<=a;j++) swap(g[i][j],g[tt][j]);
			for(int j=i+1;j<=a;j++)
			{
				long long gg=pow_(g[i][i],mod-2)%mod*g[j][i]%mod;
				for(int k=i;k<=a;k++) g[j][k]=(g[j][k]-g[i][k]*gg)%mod;
			}
		}
		for(int i=1;i<=a;i++) an=an*g[i][i]%mod;
		printf("%lld",((an+fac[a])%mod*pow_(2,mod-2)%mod+mod)%mod);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 4ms
memory: 28404kb

input:

20
20 4 15 16 11 3 7 18 9 5 13 8 6 12 2 10 1 17 14 19
-7 -11 9 -3 -20 -13 -18 15 0 8 0 12 -16 -19 8 -9 -4 -2 6 -10

output:

699910446

result:

ok 1 number(s): "699910446"

Test #2:

score: 0
Accepted
time: 4ms
memory: 28536kb

input:

20
11 6 3 18 17 19 4 8 10 15 12 16 1 13 7 14 5 20 9 2
13 9 -1 1 9 -11 -19 8 -5 -11 -4 3 17 1 8 1 0 -11 -16 -10

output:

694405422

result:

ok 1 number(s): "694405422"

Test #3:

score: 0
Accepted
time: 11ms
memory: 26504kb

input:

20
11 12 16 6 5 2 8 20 14 7 13 15 4 9 19 3 10 1 17 18
-12 11 14 -9 0 0 -4 -3 14 -4 -14 16 -1 12 -19 8 -1 1 8 10

output:

699648302

result:

ok 1 number(s): "699648302"

Test #4:

score: 0
Accepted
time: 4ms
memory: 28560kb

input:

20
12 19 16 8 7 5 15 18 10 1 2 14 6 11 9 20 4 17 13 3
-14 -13 11 -3 -8 6 -14 -4 9 -4 12 -7 -8 7 4 13 3 8 -17 11

output:

693618990

result:

ok 1 number(s): "693618990"

Test #5:

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

input:

20
19 9 2 18 10 17 7 11 16 12 3 13 8 15 14 6 5 4 1 20
13 9 16 10 4 1 -2 -11 3 11 -7 18 -15 -2 -19 9 -8 -8 4 -19

output:

700172590

result:

ok 1 number(s): "700172590"

Test #6:

score: 0
Accepted
time: 4ms
memory: 28476kb

input:

20
17 8 11 15 12 14 4 6 7 9 18 13 19 10 16 2 1 5 3 20
5 -19 6 -9 18 1 -8 -1 2 -12 7 -6 10 -4 -2 0 -9 -15 17 20

output:

700434734

result:

ok 1 number(s): "700434734"

Test #7:

score: 0
Accepted
time: 11ms
memory: 28356kb

input:

20
2 17 20 5 11 18 1 14 12 8 9 6 7 16 13 15 10 4 19 3
-2 -9 -14 -13 -12 1 -7 2 8 3 -1 -5 -4 3 -9 6 -15 11 -14 -5

output:

694143278

result:

ok 1 number(s): "694143278"

Test #8:

score: 0
Accepted
time: 10ms
memory: 28352kb

input:

20
7 12 3 15 8 2 9 11 19 4 16 10 13 14 17 6 20 1 18 5
3 10 -6 3 3 -13 -9 -5 5 -11 -16 -17 -13 5 14 4 3 1 2 9

output:

697813294

result:

ok 1 number(s): "697813294"

Test #9:

score: 0
Accepted
time: 7ms
memory: 28496kb

input:

20
5 1 7 15 9 16 12 4 17 19 13 6 11 8 20 18 10 3 14 2
-16 13 -5 -10 8 2 -5 5 -15 -18 9 0 6 18 0 10 9 -7 -16 -11

output:

700959022

result:

ok 1 number(s): "700959022"

Test #10:

score: 0
Accepted
time: 12ms
memory: 28400kb

input:

20
16 10 17 12 19 13 20 2 7 3 15 14 5 8 11 1 4 18 9 6
14 4 16 4 9 -12 -4 11 3 14 -7 -10 -19 -4 0 -1 2 -9 4 6

output:

697551150

result:

ok 1 number(s): "697551150"

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 30
Accepted
time: 7ms
memory: 28536kb

input:

15
14 4 15 10 11 3 7 1 9 5 13 8 6 12 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

985377138

result:

ok 1 number(s): "985377138"

Test #12:

score: -30
Wrong Answer
time: 10ms
memory: 28536kb

input:

15
1 2 12 4 8 13 6 5 9 3 11 10 7 14 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

985368946

result:

wrong answer 1st numbers differ - expected: '985385330', found: '985368946'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%