QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322546 | #8228. 排序 | zhouhuanyi | 100 ✓ | 3611ms | 12008kb | C++14 | 2.1kb | 2024-02-07 10:18:36 | 2024-02-07 10:18:37 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 30
#define M 10
#define K 1048576
#define mod 1000000007
using namespace std;
const int inf=(int)(1e9);
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
struct reads
{
int num,data;
};
reads dp[K+1];
reads operator + (reads a,reads b)
{
if (a.num>b.num) swap(a,b);
if (a.num==b.num) return (reads){a.num,MD(a.data+b.data)};
else return b;
}
reads F(reads x,int d)
{
return (reads){x.num+d,x.data};
}
int n,m,d[N+1],cnt[M+1],scnt[M+1],delta[N+1],p[N+1],len,st[N+1];
void get(int x)
{
for (int i=0;i<d[1];++i) delta[i]=x%(cnt[i]+1),x/=(cnt[i]+1);
return;
}
int calc()
{
int res=0,cnt,cnt2,cnt3;
bool op;
for (int i=2;i<=m;++i)
for (int j=0;j<d[i];++j)
{
len=cnt=cnt2=cnt3=0,op=1;
for (int k=j;k<n;k+=d[i]) st[++len]=p[k];
for (int k=1;k<=len-1;++k) op&=(st[k]<=st[k+1]);
if (!op)
{
for (int k=len;k>=1;--k)
{
if (st[k]==0) cnt++;
else if (st[k]==1) res+=cnt,cnt2++;
else cnt3++;
}
for (int k=j;k<n;k+=d[i])
{
if (cnt) p[k]=0,cnt--;
else if (cnt2) p[k]=1,cnt2--;
else p[k]=2,cnt3--;
}
}
}
return res;
}
int main()
{
int ds,res=0,rst=1;
n=read(),m=read();
for (int i=1;i<=m;++i) d[i]=read();
for (int i=0;i<n;++i) cnt[i%d[1]]++;
for (int i=0;i<d[1];++i) scnt[i]=cnt[i]+1,rst*=(cnt[i]+1);
for (int i=1;i<d[1];++i) scnt[i]*=scnt[i-1];
for (int i=0;i<d[1];++i) scnt[i]/=(cnt[i]+1);
for (int i=0;i<rst;++i) dp[i]=(reads){-inf,0};
dp[0]=(reads){0,1};
for (int i=0;i<rst;++i)
{
get(i);
for (int j=0;j<d[1];++j)
if (delta[j]+1<=cnt[j])
{
for (int k=0;k<n;++k) p[k]=2;
for (int k=0;k<d[1];++k)
for (int t=0;t<delta[k];++t)
p[t*d[1]+k]=0;
p[delta[j]*d[1]+j]=1,ds=calc(),dp[i+scnt[j]]=dp[i+scnt[j]]+F(dp[i],ds);
}
}
for (int i=0;i<d[1];++i) res+=((cnt[i]*(cnt[i]-1))>>1);
printf("%d %d\n",dp[rst-1].num+res,dp[rst-1].data);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 18
Accepted
Test #1:
score: 18
Accepted
time: 0ms
memory: 3720kb
input:
2 2 2 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
5 4 5 4 2 1
output:
6 4
result:
ok 2 number(s): "6 4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3752kb
input:
8 4 6 3 2 1
output:
15 4
result:
ok 2 number(s): "15 4"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3764kb
input:
8 6 8 7 5 4 2 1
output:
14 2
result:
ok 2 number(s): "14 2"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
8 3 8 7 1
output:
22 7
result:
ok 2 number(s): "22 7"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
8 1 1
output:
28 1
result:
ok 2 number(s): "28 1"
Subtask #2:
score: 27
Accepted
Dependency #1:
100%
Accepted
Test #7:
score: 27
Accepted
time: 1ms
memory: 3796kb
input:
16 2 6 1
output:
77 15
result:
ok 2 number(s): "77 15"
Test #8:
score: 0
Accepted
time: 17ms
memory: 3876kb
input:
16 8 10 9 8 7 6 5 4 1
output:
57 5
result:
ok 2 number(s): "57 5"
Test #9:
score: 0
Accepted
time: 20ms
memory: 3856kb
input:
16 10 10 9 8 7 6 5 4 3 2 1
output:
57 3
result:
ok 2 number(s): "57 3"
Test #10:
score: 0
Accepted
time: 16ms
memory: 3876kb
input:
16 7 10 9 8 6 5 4 1
output:
49 1
result:
ok 2 number(s): "49 1"
Test #11:
score: 0
Accepted
time: 4ms
memory: 3808kb
input:
16 4 7 6 2 1
output:
52 9
result:
ok 2 number(s): "52 9"
Subtask #3:
score: 21
Accepted
Dependency #2:
100%
Accepted
Test #12:
score: 21
Accepted
time: 2ms
memory: 3976kb
input:
22 3 5 3 1
output:
100 1
result:
ok 2 number(s): "100 1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
22 1 1
output:
231 1
result:
ok 2 number(s): "231 1"
Test #14:
score: 0
Accepted
time: 160ms
memory: 4600kb
input:
22 4 10 8 3 1
output:
97 4
result:
ok 2 number(s): "97 4"
Test #15:
score: 0
Accepted
time: 175ms
memory: 5792kb
input:
22 5 10 7 6 3 1
output:
92 70
result:
ok 2 number(s): "92 70"
Test #16:
score: 0
Accepted
time: 191ms
memory: 4632kb
input:
22 6 10 9 8 7 3 1
output:
97 1
result:
ok 2 number(s): "97 1"
Test #17:
score: 0
Accepted
time: 271ms
memory: 4572kb
input:
22 10 10 9 8 7 6 5 4 3 2 1
output:
109 1
result:
ok 2 number(s): "109 1"
Subtask #4:
score: 10
Accepted
Test #18:
score: 10
Accepted
time: 2ms
memory: 3984kb
input:
14 2 10 1
output:
61 210
result:
ok 2 number(s): "61 210"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
18 2 2 1
output:
117 1
result:
ok 2 number(s): "117 1"
Test #20:
score: 0
Accepted
time: 475ms
memory: 9328kb
input:
30 2 9 1
output:
264 84
result:
ok 2 number(s): "264 84"
Test #21:
score: 0
Accepted
time: 367ms
memory: 8828kb
input:
29 2 9 1
output:
253 36
result:
ok 2 number(s): "253 36"
Test #22:
score: 0
Accepted
time: 60ms
memory: 4520kb
input:
25 2 8 1
output:
195 8
result:
ok 2 number(s): "195 8"
Subtask #5:
score: 24
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #23:
score: 24
Accepted
time: 2056ms
memory: 12004kb
input:
30 4 10 9 5 1
output:
188 40
result:
ok 2 number(s): "188 40"
Test #24:
score: 0
Accepted
time: 3347ms
memory: 11944kb
input:
30 9 10 9 8 7 6 5 4 3 1
output:
184 6
result:
ok 2 number(s): "184 6"
Test #25:
score: 0
Accepted
time: 3124ms
memory: 12000kb
input:
30 8 10 9 8 7 4 3 2 1
output:
154 1
result:
ok 2 number(s): "154 1"
Test #26:
score: 0
Accepted
time: 3193ms
memory: 11980kb
input:
30 8 10 8 7 6 5 4 3 1
output:
155 1
result:
ok 2 number(s): "155 1"
Test #27:
score: 0
Accepted
time: 2767ms
memory: 11944kb
input:
30 6 10 8 6 4 3 1
output:
150 4
result:
ok 2 number(s): "150 4"
Test #28:
score: 0
Accepted
time: 3611ms
memory: 12008kb
input:
30 10 10 9 8 7 6 5 4 3 2 1
output:
184 6
result:
ok 2 number(s): "184 6"
Test #29:
score: 0
Accepted
time: 1905ms
memory: 10540kb
input:
29 6 10 9 7 5 3 1
output:
129 200
result:
ok 2 number(s): "129 200"
Extra Test:
score: 0
Extra Test Passed