QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573281#6397. Master of Both IIIshstyle#WA 4ms43988kbC++202.0kb2024-09-18 18:00:272024-09-18 18:00:28

Judging History

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

  • [2024-09-18 18:00:28]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:43988kb
  • [2024-09-18 18:00:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=(1<<22)+10,mod=998244353;
typedef long long ll;
typedef pair<ll,ll> PII;

ll n,a[N];
int p[N];
int l[N],r[N];
mt19937 rnd(time(0));

ll mi[N];
ll dp[30][30];
ll ddp[N];

vector<PII> e[N];

bool tf[N];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    a[0]=a[n];
    memset(dp,0x3f,sizeof dp);
    dp[0][0]=0;
    // for(int i=0;i<n;i++) dp[0][i]=a[i];
    for(int i=1;i<n;i++){
        for(int j=0;j<n;j++){
            int nw=(j+i)%n;
            dp[i][nw]=min(dp[i-1][nw],dp[i-1][j]+a[i]);

        }
        // for(int j=0;j<n;j++) cout<<dp[i][j]<<" ";
        // cout<<endl;

    }
    for(int i=0;i<n;i++){
        a[i]=dp[n-1][i];
        // cout<<a[i]<<endl;
    }
    
    for(int i=1;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                for(int k=0;k<n;k++){
                    int nw=(j-k+n)%n;
                    int nnw=i|(1<<nw);
                    e[i].push_back({nnw,a[k]});
                }
            }
        }
    }
    

    memset(ddp,0x3f,sizeof ddp);
    queue<int> q;
    q.push(1);
    ddp[1]=0;
    tf[1]=1;
    while(q.size()){
        int t=q.front();
        q.pop();
        for(auto [j,w]:e[t]){
            ddp[j]=min(ddp[j],ddp[t]+w);
            // cout<<j<<" "<<w<<endl;
            if(!tf[j]){
                tf[j]=1;
                q.push(j);
            }
        }
    }
    // for(int i=1;i<(1<<n);i++) cout<<ddp[i]<<endl;
    ddp[1]=0;
    for(int i=(1<<n)-1;i>0;i--){
        for(int j=0;j<n;j++){
            if(!((i>>j)&1)){
                int nw=i^(1<<j);
                if(nw!=0){
                    ddp[i]=min(ddp[i],ddp[nw]);
                }
            }
        }
    }
    
    ll ans=0;
    for(int i=1;i<(1<<n);i++){
        // cout<<ddp[i]<<endl;;
        ll res=ddp[i]%mod*i%mod;
        ans=(ans+res)%mod;
    }
    cout<<ans<<endl;

    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 42608kb

input:

3
2 1 2

output:

45

result:

ok 1 number(s): "45"

Test #2:

score: 0
Accepted
time: 4ms
memory: 42604kb

input:

4
1919810 999999998 999999997 114114514

output:

152175989

result:

ok 1 number(s): "152175989"

Test #3:

score: 0
Accepted
time: 4ms
memory: 42604kb

input:

3
842160586 705327547 868243944

output:

78597628

result:

ok 1 number(s): "78597628"

Test #4:

score: 0
Accepted
time: 4ms
memory: 42612kb

input:

5
198327434 147392532 760837755 771109105 676721155

output:

751568230

result:

ok 1 number(s): "751568230"

Test #5:

score: -100
Wrong Answer
time: 3ms
memory: 43988kb

input:

10
831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703

output:

458771697

result:

wrong answer 1st numbers differ - expected: '308170104', found: '458771697'