QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775989 | #9785. Shrooks | ucup-team3161# | WA | 1ms | 7792kb | C++14 | 4.6kb | 2024-11-23 17:13:27 | 2024-11-23 17:13:27 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define ll __int128
//#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
#define mod 998244353
struct modint{
unsigned int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x<o.x?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 500005
#define inf 0x3f3f3f3f
int n,p[maxn],pos[maxn];
map< array<int,6> ,modint>f,g;
int nl[maxn],nr[maxn];
void work()
{
n=read();
f.clear(),g.clear();
For(i,1,n) pos[i]=0;
// For(i,1,n){
// p[i]=read();
// if(p[i]!=-1)pos[p[i]]=i;
// }
For(i,1,n+1)nl[i]=1,nr[i]=n;
for(int l=1,r=n;l<r;l++,r--){
g.clear();
int nl,nr;
if(n%2==0){
nl=n/2-l;
nr=n/2+l+1;
}else{
nl=n/2+2-l-1;
nr=n/2+l+1;
}
nl=max(nl,1);
nr=min(nr,n);
::nl[l]=nl;
::nr[l]=nr;
}
array<int,6> fir={n/2+1,n/2,nl[1],nr[1],nl[1],nr[1]};
f[fir]=1;
for(int l=1,r=n;l<r;++l,--r){
// cout<<"solve "<<l<<" "<<r<<" "<<nl[l]<<" "<<nr[l]<<"\n";
int dif=r-l-1; dif=n-dif;
// cout<<"dif "<<dif<<"\n";
for(auto [it,w]:f){
auto [l0,r0,l1,r1,l2,r2]=it;
// cout<<"it: "<<l0<<" "<<r0<<" "<<l1<<" "<<r1<<" "<<l2<<" "<<r2<<"\n";
// cout<<"w: "<<w.x<<"\n";
auto chk=[&](int p1,int p2){
// cout<<"chk "<<p1<<" "<<p2<<"\n";
if((pos[l]&&p1!=pos[l]) || (pos[r]&&p2!=pos[r])) return;
if(p1!=p2 && p1>=l1 && p1<=r1 && p2>=l2 && p2<=r2){
// cout<<"ok! "<<p1<<" "<<p2<<" "<<w.x<<"\n";
int fl0=min(l0,min(p1,p2));
int fr0=max(r0,max(p1,p2));
int fl1=max(l1-1,p2-dif);
int fr1=min(r1+1,p2+dif);
int fl2=max(l2-1,p1-dif);
int fr2=min(r2+1,p1+dif);
fl1=max(fl1,nl[l+1]);
fl2=max(fl2,nl[l+1]);
fr1=min(fr1,nr[l+1]);
fr2=min(fr2,nr[l+1]);
// cout<<"--> "<<fl0<<" "<<fr0<<" "<<fl1<<" "<<fr1<<" "<<fl2<<" "<<fr2<<"\n";
g[{fl0,fr0,fl1,fr1,fl2,fr2}]+=w;
}
};
if(n%2 && (l==1)){
int ps=(n+1)/2;
chk(ps-1,ps);
chk(ps,ps-1);
chk(ps+1,ps);
chk(ps,ps+1);
continue;
}
chk(l0-1,r0+1);
chk(r0+1,l0-1);
chk(l0-2,l0-1);
chk(l0-1,l0-2);
chk(r0+1,r0+2);
chk(r0+2,r0+1);
}
swap(f,g); g.clear();
}
modint res=0;
for(auto [it,w]:f) {
if(n&1){
auto [l0,r0,l1,r1,l2,r2]=it;
int ps=(l0==1?n:1);
if(!(l1-1<=ps && ps<=r1+1)) continue;
if(!(l2-1<=ps && ps<=r2+1)) continue;
if(pos[n/2+1] && ps!=pos[n/2+1]) continue;
}
res+=w;
}
cout<<res.x<<"\n";
}
signed main()
{
int T=read();
while(T--)work();
return 0;
}
/*
*/
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7792kb
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:
2 1 2 4 0 0
result:
wrong answer 1st numbers differ - expected: '1', found: '2'