QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#844376#8228. 排序Wanye100 ✓2314ms73316kbC++145.1kb2025-01-05 20:22:022025-01-05 20:22:03

Judging History

你现在查看的是最新测评结果

  • [2025-01-05 20:22:03]
  • 评测
  • 测评结果:100
  • 用时:2314ms
  • 内存:73316kb
  • [2025-01-05 20:22:02]
  • 提交

answer

#include<vector>
#include<iostream>
#include<map>
#include<cstring>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#define ll int
#define mod 1000000007
using namespace std;
inline ll add(ll x){return x>=mod?x-mod:x;}
inline pair<ll,ll> operator+(const pair<ll,ll> &a,const ll &b){return make_pair(a.first+b,a.second);}
inline pair<ll,ll> operator+(const pair<ll,ll> &a,const pair<ll,ll> &b){
    if(a.first==b.first) return make_pair(a.first,add(a.second+b.second));
    else if(a.first<b.first) return b;
    else return a;
}
vector<ll> pos[15],emp;
ll n,m,i,j,k,d[15],full;
ll vis[2000005];
pair<ll,ll> maps[2000005];
vector<bool> vis2[15][35];
vector<ll> maps2[15][35];
ll prod[15][35][15],wz[15][35][15],cntt[15][15],f[35][15];
inline void write(pair<ll,ll> a){cout<<a.first<<" "<<a.second<<endl;}
ll t,cnts[15];
inline ll get(ll step,ll zero,ll idd,ll pos){
    ll ff = f[pos][step];
    if(ff==f[zero][step]){
        if(pos==zero) return 0;
        if(pos<zero) return -1;
        return 1;
    }
    if(pos/d[step]+1+(idd/prod[step][zero][ff])%(wz[step][zero][ff])<=cntt[step][ff]) return -1;
    return 1;
}
inline void work(ll Step,ll Zero,ll Idd,ll &swap_count,ll &zero,ll &idd2,ll step) {
    zero = t-1;
    for (ll i = 0; i < t; i++) {
        ll temp = 0,endid = -1;
        cnts[i] = 0;
        for (ll j = i; j < n; j += t){
            ll now = get(Step,Zero,Idd,j);
            endid = j;
            if(now == 0) temp = 1;
            if(now == 1) cnts[i]++;
            if(now == -1) swap_count += temp;
        }
        if(temp) zero=endid-t*cnts[i];
        else idd2+=prod[step][zero][i]*cnts[i];
    }
}
inline ll dfs2(ll step,ll zero,ll idd){
    if(vis2[step-1][zero][idd]) return maps2[step-1][zero][idd];
    if(step>m) return 0;
    ll ans = 0,zero2 = -1,idd2 = 0;
    t = d[step];
    work(step-1,zero,idd,ans,zero2,idd2,step);
    ans += dfs2(step+1,zero2,idd2);
    return vis2[step-1][zero][idd] = 1,maps2[step-1][zero][idd] = ans;
}
ll bin[15];
inline pair<ll,ll> dfs(ll id){
    if(id==full-1) return make_pair(0,1);
    if(vis[id]) return maps[id];
    pair<ll,ll> ans = make_pair(-1,0);
    for(ll i=0;i<emp.size();i++){
        if(emp[i]<pos[i].size()){
            ll idd = 0;
            for(ll j=0;j<emp.size();j++) if(j!=i) idd+=prod[1][pos[i][emp[i]]][j]*(pos[j].size()-emp[j]);
            emp[i]++;
            ans = (ans+(dfs(id+bin[i])+dfs2(2,pos[i][emp[i]-1],idd)+(pos[i].size()-emp[i])));
            emp[i]--;
        }
    }
    return vis[id]=1,maps[id]=ans;
}
ll cnt[15];
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>m;
    for(i=1;i<=m;i++) cin>>d[i];
    memset(cnt,0,sizeof(cnt));
    for(j=0;j<n;j++) cnt[j%d[1]]++;
    ll noww = 1;
    for(j=0;j<d[1];j++) bin[j]=noww,noww*=(cnt[j]+1);
    full=noww;
    for(i=1;i<=m;i++){
        memset(cnt,0,sizeof(cnt));
        for(j=0;j<n;j++) cnt[j%d[i]]++,f[j][i]=j%d[i];
        for(j=0;j<d[i];j++) cntt[i][j]=cnt[j];
        for(j=0;j<n;j++){
            memset(cnt,0,sizeof(cnt));
            for(k=0;k<n;k++){
                if(k%d[i]==j%d[i]) continue;
                cnt[k%d[i]]++;
            }
            ll now=1;
            for(k=0;k<d[i];k++) prod[i][j][k]=now,now*=(cnt[k]+1),wz[i][j][k]=cnt[k]+1;
            vis2[i][j].resize(now),maps2[i][j].resize(now);
        }
    }
    for(i=0;i<n;i++) pos[i%d[1]].push_back(i);
    for(i=0;i<d[1];i++) emp.push_back(0);
    write(dfs(0));
    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: 3652kb

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

score: 18
Accepted
time: 0ms
memory: 3692kb

input:

5 4
5 4 2 1

output:

6 4

result:

ok 2 number(s): "6 4"

Test #3:

score: 18
Accepted
time: 1ms
memory: 3768kb

input:

8 4
6 3 2 1

output:

15 4

result:

ok 2 number(s): "15 4"

Test #4:

score: 18
Accepted
time: 1ms
memory: 3720kb

input:

8 6
8 7 5 4 2 1

output:

14 2

result:

ok 2 number(s): "14 2"

Test #5:

score: 18
Accepted
time: 1ms
memory: 3632kb

input:

8 3
8 7 1

output:

22 7

result:

ok 2 number(s): "22 7"

Test #6:

score: 18
Accepted
time: 0ms
memory: 3700kb

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: 2ms
memory: 3708kb

input:

16 2
6 1

output:

77 15

result:

ok 2 number(s): "77 15"

Test #8:

score: 27
Accepted
time: 12ms
memory: 6584kb

input:

16 8
10 9 8 7 6 5 4 1

output:

57 5

result:

ok 2 number(s): "57 5"

Test #9:

score: 27
Accepted
time: 16ms
memory: 4496kb

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: 27
Accepted
time: 16ms
memory: 4564kb

input:

16 7
10 9 8 6 5 4 1

output:

49 1

result:

ok 2 number(s): "49 1"

Test #11:

score: 27
Accepted
time: 4ms
memory: 3864kb

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: 3908kb

input:

22 3
5 3 1

output:

100 1

result:

ok 2 number(s): "100 1"

Test #13:

score: 21
Accepted
time: 0ms
memory: 3612kb

input:

22 1
1

output:

231 1

result:

ok 2 number(s): "231 1"

Test #14:

score: 21
Accepted
time: 144ms
memory: 8476kb

input:

22 4
10 8 3 1

output:

97 4

result:

ok 2 number(s): "97 4"

Test #15:

score: 21
Accepted
time: 151ms
memory: 9408kb

input:

22 5
10 7 6 3 1

output:

92 70

result:

ok 2 number(s): "92 70"

Test #16:

score: 21
Accepted
time: 152ms
memory: 11504kb

input:

22 6
10 9 8 7 3 1

output:

97 1

result:

ok 2 number(s): "97 1"

Test #17:

score: 21
Accepted
time: 155ms
memory: 10588kb

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: 5720kb

input:

14 2
10 1

output:

61 210

result:

ok 2 number(s): "61 210"

Test #19:

score: 10
Accepted
time: 0ms
memory: 3664kb

input:

18 2
2 1

output:

117 1

result:

ok 2 number(s): "117 1"

Test #20:

score: 10
Accepted
time: 888ms
memory: 23924kb

input:

30 2
9 1

output:

264 84

result:

ok 2 number(s): "264 84"

Test #21:

score: 10
Accepted
time: 687ms
memory: 21184kb

input:

29 2
9 1

output:

253 36

result:

ok 2 number(s): "253 36"

Test #22:

score: 10
Accepted
time: 96ms
memory: 6592kb

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: 2205ms
memory: 63384kb

input:

30 4
10 9 5 1

output:

188 40

result:

ok 2 number(s): "188 40"

Test #24:

score: 24
Accepted
time: 2194ms
memory: 72852kb

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: 24
Accepted
time: 2184ms
memory: 71632kb

input:

30 8
10 9 8 7 4 3 2 1

output:

154 1

result:

ok 2 number(s): "154 1"

Test #26:

score: 24
Accepted
time: 2301ms
memory: 58592kb

input:

30 8
10 8 7 6 5 4 3 1

output:

155 1

result:

ok 2 number(s): "155 1"

Test #27:

score: 24
Accepted
time: 2314ms
memory: 55592kb

input:

30 6
10 8 6 4 3 1

output:

150 4

result:

ok 2 number(s): "150 4"

Test #28:

score: 24
Accepted
time: 2217ms
memory: 73316kb

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: 24
Accepted
time: 1621ms
memory: 51144kb

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