QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363054#8228. 排序XY_Eleven100 ✓3142ms503888kbC++235.3kb2024-03-23 18:07:222024-03-23 18:07:23

Judging History

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

  • [2024-03-23 18:07:23]
  • 评测
  • 测评结果:100
  • 用时:3142ms
  • 内存:503888kb
  • [2024-03-23 18:07:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 _x0_
#define y1 _y1_
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; }
template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; }
template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; }
template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_)
{ if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; }
LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); }
void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); }
template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
cint N=32,N_=30,M=12,P=7.02e6;
int n,m,m_,p;
int a[M];
vector <int> v;
#define ar array <int,N_>
vector <ar> g; 
bool b[N];
void dfs(int f,int k)
{
    if(k>=n) return (void)(v.pb(f));
    if(k<a[m_]||(k>=a[m_]&&b[k-a[m_]])) b[k]=true,dfs(f|(1<<k),k+1);
    b[k]=false,dfs(f,k+1);
}
void dfs2(int f,int k)
{
    if(k>=n) return (void)(v.pb(f));
    if(k<a[m_]||(k>=a[m_]&&!b[k-a[m_]])) b[k]=false,dfs2(f,k+1);
    b[k]=true,dfs2(f|(1<<k),k+1);
}
int c[N],mx[N];
unordered_map <int,ar> fun,fun2;
ar work(int w,int k)
{
    if(k>m)
    {
        ar t;
        For_(i,0,n) t[i]=0;
        return (fun[w]=t);
    }
    int w2=w;
    For_(i,0,n)
    {
        exc(!(w2>>i&1));
        int i2=i;
        while(i2>=a[k]&&!(w2>>(i2-a[k])&1))
        {
            w2^=(1<<i2-a[k])|(1<<i2);
            i2-=a[k];
        }
    }
    ar t;
    auto t2=fun2[k==m?0:w2];
    int cnt=0;
    For_(i,0,n) c[i]=((w>>i&1)?i+1:0),t[i]=0;
    For(i,0,n-1)
    {
        for(int i2=i;i2>=a[k];i2-=a[k])
        {
            if(c[i2]>c[i2-a[k]])
            {
                if(!c[i2-a[k]]) t[c[i2]-1]++;
                swap(c[i2],c[i2-a[k]]);
            }
            else break;
        }
    }
    For_(i,0,a[k]) mx[i]=0;
    For_(i,0,n) if(c[i]) mx[i%a[k]]=t2[i];
    For_(i,0,n) if(c[i]) t[c[i]-1]+=mx[i%a[k]];
    return (fun[w]=t);
}
int f[P],dp[P];
unordered_map <int,int> mp;
void main_solve()
{
    inpr(n,m);
    For(i,1,m) inint(a[i]);
    for(m_=m;m_>=1;m_--)
    {
        fun2.clear();
        swap(fun,fun2);
        v.clear();
        dfs(0,0);
        sort(all(v));
        // printf("m_=%d\n",m_);
        // for(auto i:v) printf("%d ",i);
        // printf("\n");
        for(auto i:v) work(i,m_+1);
    }
    fun2.clear();
    swap(fun,fun2);
    v.clear();
    m_=1;
    dfs2(0,0);
    sort(all(v));
    for(auto i:v) g.pb(work(i,1));
    p=0; for(auto i:v) mp[i]=p++;
    memset(f,0xc0,p*sizeof(int));
    memset(dp,0,p*sizeof(int));
    f[0]=0,dp[0]=1;
    For_(i,0,p)
    {
        int t=v[i];
        For_(j,0,n)
        {
            exc((t>>j&1)||mp.find(t|(1<<j))==mp.end());
            int i2=mp[t|(1<<j)];
            int c=f[i]+g[i2][j];
            exc(c<f[i2]);
            if(c==f[i2]) add(dp[i2],dp[i]);
            else dp[i2]=dp[i];
            f[i2]=c;
        }
    }
    /*For_(i,0,p)
    {
        For_(j,0,n) printf("%d",v[i]>>j&1);
        printf(": %d %d\n> ",f[i],dp[i]);
        for(auto j:g[i]) printf("%d ",j);
        printf("\n");
    }*/
    printf("%d %d\n",f[p-1],dp[p-1]);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out1.txt","w",stdout);
    // rsand(time(NULL));
    // main_init();
    // int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*
2 2 2 1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 18
Accepted

Test #1:

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

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5988kb

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

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

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

input:

8 3
8 7 1

output:

22 7

result:

ok 2 number(s): "22 7"

Test #6:

score: 0
Accepted
time: 1ms
memory: 6192kb

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: 0ms
memory: 6956kb

input:

16 2
6 1

output:

77 15

result:

ok 2 number(s): "77 15"

Test #8:

score: 0
Accepted
time: 20ms
memory: 11144kb

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

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: 14ms
memory: 11108kb

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: 6ms
memory: 7256kb

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: 8ms
memory: 7480kb

input:

22 3
5 3 1

output:

100 1

result:

ok 2 number(s): "100 1"

Test #13:

score: 0
Accepted
time: 1ms
memory: 5908kb

input:

22 1
1

output:

231 1

result:

ok 2 number(s): "231 1"

Test #14:

score: 0
Accepted
time: 169ms
memory: 55700kb

input:

22 4
10 8 3 1

output:

97 4

result:

ok 2 number(s): "97 4"

Test #15:

score: 0
Accepted
time: 158ms
memory: 58584kb

input:

22 5
10 7 6 3 1

output:

92 70

result:

ok 2 number(s): "92 70"

Test #16:

score: 0
Accepted
time: 204ms
memory: 58028kb

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: 208ms
memory: 56632kb

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: 5ms
memory: 8128kb

input:

14 2
10 1

output:

61 210

result:

ok 2 number(s): "61 210"

Test #19:

score: 0
Accepted
time: 1ms
memory: 6024kb

input:

18 2
2 1

output:

117 1

result:

ok 2 number(s): "117 1"

Test #20:

score: 0
Accepted
time: 1214ms
memory: 249644kb

input:

30 2
9 1

output:

264 84

result:

ok 2 number(s): "264 84"

Test #21:

score: 0
Accepted
time: 945ms
memory: 207560kb

input:

29 2
9 1

output:

253 36

result:

ok 2 number(s): "253 36"

Test #22:

score: 0
Accepted
time: 136ms
memory: 46732kb

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: 2986ms
memory: 502348kb

input:

30 4
10 9 5 1

output:

188 40

result:

ok 2 number(s): "188 40"

Test #24:

score: 0
Accepted
time: 3102ms
memory: 503196kb

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: 3097ms
memory: 503888kb

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: 2925ms
memory: 503264kb

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: 2823ms
memory: 503388kb

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: 3142ms
memory: 503672kb

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: 2165ms
memory: 392492kb

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