QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775179 | #9785. Shrooks | ucup-team1004# | WA | 18ms | 3872kb | C++17 | 2.2kb | 2024-11-23 14:57:59 | 2024-11-23 14:58:02 |
Judging History
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 flip1(){
if(n&1){
for(int i=1;i<=n;i++)swap(a[i],b[i]);
}else{
reverse(a+1,a+1+n);
for(int i=1;i<=n;i++)if(b[i]!=-1)b[i]=n+1-b[i];
}
}
void flip2(){
if(n&1){
for(int i=1;i<=n;i++)swap(a[i],b[i]);
reverse(a+1,a+1+n);
reverse(b+1,b+1+n);
}else{
reverse(b+1,b+1+n);
for(int i=1;i<=n;i++)if(a[i]!=-1)a[i]=n+1-a[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{
// if(n==4)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();
flip1();
calc();
flip2();
calc();
flip1();
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: 3764kb
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: 3872kb
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: 18ms
memory: 3760kb
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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 0 0 0 0 0 5 0 0 1 0 0 0 0 0 0 0 0 1 0 0 3 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 62nd numbers differ - expected: '2', found: '1'