QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357466 | #1241. Raid | Diu | WA | 4ms | 105484kb | C++14 | 2.8kb | 2024-03-18 21:33:48 | 2024-03-18 21:33:49 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=42,M=3.2e6;
int n,a[N],vis[N];
int b[N],m1,c[N],m2;
int p[N],q[N];
struct node{
int x;ll y;
node(int xx=N*N,int yy=0){x=xx,y=yy;}
}f[M],g[M];
const node empty;
int sz[M];
node operator +(node a,int b){
return (node){a.x+b,a.y};
}
node operator +(node a,node b){
if(a.x<b.x)return a;
if(a.x>b.x)return b;
return (node){a.x,a.y+b.y};
}
node operator +=(node &a,node b){
return a=a+b;
}
signed main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
f[0]=(node){0,1};
p[0]=1;
for(int i=1;i<=n;i++){
// printf("Work:%d\n",i);
int x=0;
if(vis[a[i]-1]&&vis[a[i]+1]){
m2=m1-1;
x=vis[a[i]-1];
for(int j=1;j<x;j++)c[j]=b[j];
c[x]=b[x]+b[x+1]+1;
for(int j=x+1;j<=m2;j++)c[j]=b[j+1];
q[0]=1;
for(int j=1;j<=m2;j++)q[j]=q[j-1]*(c[j]+1);
for(int j=1;j<=m1;j++){
for(int s=0;s<p[j-1];s++)for(int k=1;k<=b[j];k++){
sz[s+k*p[j-1]]=sz[s]+(j>x?k:0);
}
}
// printf("Now:%d\n",x);
// for(int j=1;j<=m1;j++)printf("%d ",p[j]);puts("");
// for(int j=1;j<=m2;j++)printf("%d ",q[j]);puts("");
for(int s=0;s<p[m1];s++){
int t=s%p[x-1]+s/p[x+1]*q[x]+(s/p[x-1]%(b[x]+1)+s/p[x]%(b[x+1]+1))*q[x-1];
g[t]+=f[s],g[t+q[x-1]]+=(f[s]+sz[s]);
// printf("%d %d\n",s,t);
}
vis[a[i]]=x;
for(int j=a[i]+1;j<=n;j++)if(vis[j])--vis[j];
}else if(vis[a[i]-1]||vis[a[i]+1]){
x=vis[a[i]-1]+vis[a[i]+1];
int y=vis[a[i]-1]?x:x-1;
m2=m1;
for(int j=1;j<=m2;j++)c[j]=b[j];
p[0]=1,q[0]=1;
for(int j=1;j<=m1;j++)p[j]=p[j-1]*(b[j]+1);
for(int j=1;j<=m2;j++)q[j]=q[j-1]*(c[j]+1);
for(int j=1;j<=m1;j++){
for(int s=0;s<p[j-1];s++)for(int k=1;k<=b[j];k++){
sz[s+k*p[j-1]]=sz[s]+(j>y?k:0);
}
}
for(int s=0;s<p[m1];s++){
int t=s%p[x]+s/p[x]*q[x];
g[t]=f[s],g[t+q[x-1]]+=(f[s]+sz[s]);
}
vis[a[i]]=x;
}else{
m2=m1+1;
int l=a[i];
while(l&&!vis[l])--l;
int x=vis[l]+1;
for(int j=1;j<x;j++)c[j]=b[j];
c[x]=1;
for(int j=x+1;j<=m2;j++)c[j]=b[j-1];
q[0]=1;
for(int j=1;j<=m2;j++)q[j]=q[j-1]*(c[j]+1);
for(int j=1;j<=m1;j++){
for(int s=0;s<p[j-1];s++)for(int k=1;k<=b[j];k++){
sz[s+k*p[j-1]]=sz[s]+(j>=x?k:0);
}
}
for(int s=0;s<p[m1];s++){
int t=s%p[x-1]+s/p[x-1]*q[x];
g[t]=f[s],g[t+q[x-1]]+=(f[s]+sz[s]);
}
vis[a[i]]=x;
for(int j=a[i]+1;j<=n;j++)if(vis[j])++vis[j];
}
m1=m2;
for(int j=1;j<=m1;j++)b[j]=c[j];
for(int j=0;j<=m1;j++)p[j]=q[j];
for(int s=0;s<p[m1];s++)f[s]=g[s],g[s]=empty;
// for(int j=1;j<=m1;j++)printf("%d ",b[j]);puts("");
// for(int j=1;j<=n;j++)printf("%d ",vis[j]);puts("");
// for(int s=0;s<p[m1];s++)printf("Node:%d %d %d\n",s,f[s].x,f[s].y);
}
for(int i=1;i<=n;i++)printf("%d %lld\n",f[i].x,f[i].y);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 105484kb
input:
5 5 3 1 4 2
output:
0 5 0 3 1 2 3 1 7 1
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 4ms
memory: 104260kb
input:
1 1
output:
0 1
result:
ok 2 number(s): "0 1"
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 105028kb
input:
2 1 2
output:
0 1 1764 0
result:
wrong answer 2nd numbers differ - expected: '2', found: '1'