QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#775101#9785. Shrooksucup-team1004#WA 19ms3916kbC++172.0kb2024-11-23 14:43:562024-11-23 14:43:58

Judging History

This is the latest submission verdict.

  • [2024-11-23 14:43:58]
  • Judged
  • Verdict: WA
  • Time: 19ms
  • Memory: 3916kb
  • [2024-11-23 14:43:56]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=2e5+10,mod=998244353;
int T,n,a[N],b[N];
void rev(){
	reverse(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		if(b[i]!=-1)b[i]=n+1-b[i];
	}
}
void flip(){
	for(int i=1;i<=n;i++)swap(a[i],b[i]);
}
int ans;
void calc(){
	if(n&1){
		if(a[1]==-1||a[1]==(n+1)/2){
			int res=1;
			for(int l=2,r=n,L=(n-1)/2,R=L+2;l<r;l++,r--,L--,R++){
				for(int x:{l,r})if(a[x]!=-1&&a[x]!=L&&a[x]!=R)res=0;
				if(a[l]==-1&&a[r]==-1)res=res*2%mod;
			}
			(ans+=res)%=mod;
		}
		int res=1;
		for(int i=1,j=(n+1)/2;i<=n;i++,j=j>1?j-1:n){
			if(a[i]!=-1&&a[i]!=j)res=0;
		}
		(ans+=mod-res)%=mod;
	}else{
		// debug(ary(a,1,n));
		if((a[1]==-1||a[1]==n/2+1)&&(a[n/2+1]==-1||a[n/2+1]==1)){
			int res=1;
			for(int l=2,r=n,L=n/2,R=L+2;l<r;l++,r--,L--,R++){
				for(int x:{l,r})if(a[x]!=-1&&a[x]!=L&&a[x]!=R)res=0;
				if(a[l]==-1&&a[r]==-1)res=res*2%mod;
			}
			(ans+=res)%=mod;
		}
		int res=1;
		for(int i=1,j=n/2+1;i<=n;i++,j=j%n+1){
			if(a[i]!=-1&&a[i]!=j)res=0;
		}
		(ans+=mod-res)%=mod;
	}
}
void work(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	fill(b+1,b+1+n,-1);
	for(int i=1;i<=n;i++){
		if(a[i]==-1)continue;
		if(b[a[i]]!=-1)return puts("0"),void();
		b[a[i]]=i;
	}
	if(n==2){
		printf("%d\n",1+(a[1]==-1&&a[2]==-1));
		return;
	}
	ans=0;
	calc();
	rev();
	calc();
	flip();
	calc();
	rev();
	calc();
	if(n%2==0){
		int res=1;
		for(int l=1,r=n,L=n/2,R=L+1;l<r;l++,r--,L--,R++){
			for(int x:{l,r})if(a[x]!=-1&&a[x]!=L&&a[x]!=R)res=0;
			if(a[l]==-1&&a[r]==-1)res=res*2%mod;
		}
		(ans+=res)%=mod;	
	}
	printf("%d\n",ans);
}
int main(){
	for(scanf("%d",&T);T--;)work();
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3908kb

input:

6
2
1 2
3
-1 -1 -1
4
1 -1 -1 -1
5
1 -1 -1 -1 5
6
3 -1 -1 -1 -1 4
10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

1
4
1
0
6
92

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

6
2
1 2
3
-1 -1 -1
4
1 -1 -1 -1
5
1 -1 -1 -1 5
6
3 -1 -1 -1 -1 4
10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

1
4
1
0
6
92

result:

ok 6 numbers

Test #3:

score: -100
Wrong Answer
time: 19ms
memory: 3916kb

input:

26874
7
-1 -1 7 1 5 3 -1
7
-1 -1 5 3 6 -1 7
7
-1 7 -1 2 3 6 -1
7
-1 2 7 1 5 3 -1
7
3 -1 2 6 1 4 -1
7
4 -1 5 6 1 -1 3
7
-1 -1 4 -1 7 2 -1
7
-1 6 -1 5 4 3 -1
7
6 7 1 2 5 4 -1
7
-1 5 -1 4 2 3 6
7
-1 4 3 5 7 6 -1
7
6 -1 -1 -1 7 5 -1
7
-1 -1 2 -1 4 -1 3
7
-1 -1 2 -1 6 -1 4
7
-1 5 6 2 7 4 -1
7
-1 -1 6 -1 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
2
0
2
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
2
2
0
0
0
0
0
6
0
0
1
0
0
0
0
0
0
0
0
1
0
0
2
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
2
1
0
0
0
0
0
0
0
...

result:

wrong answer 77th numbers differ - expected: '3', found: '2'