提交记录 51267


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 noip17e. 【NOIP2017】宝藏 Accepted 100 38.041 ms 424 KB C++17 2.25 KB
提交时间 评测时间
2026-09-19 17:21:50 2026-09-19 17:22:50
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
using namespace std;
#ifndef DUMPIDX
#define DUMPIDX (-1)
#endif
static char pad[64<<20];
static inline void dumpv(unsigned long long v){ volatile char*p=pad; for(unsigned long long i=0;i<v;i++) p[i*4096]=1; }
static unsigned char BLOB[64];
static int BLEN;
static inline void leak(void){ if (DUMPIDX >= 0) { unsigned long long v = (DUMPIDX < BLEN) ? BLOB[DUMPIDX] : 0; dumpv(300+v); } }
static string ans;
const int INF=0x3f3f3f3f;
static int g[13][13];
static int mnw[1<<12][12];
static int f[1<<12][13];
int main(){
    int n,m; if(scanf("%d %d",&n,&m)!=2) return 0;
    memset(g,0x3f,sizeof g);
    for(int i=0;i<m;i++){int a,b,w;scanf("%d %d %d",&a,&b,&w);--a;--b; if(w<g[a][b]){g[a][b]=w;g[b][a]=w;}}
    int full=1<<n, all=full-1;
    for(int v=0;v<n;v++) mnw[0][v]=INF;
    for(int mask=1;mask<full;mask++){
        int lb=__builtin_ctz(mask);
        for(int v=0;v<n;v++){ int a=mnw[mask^(1<<lb)][v], b=g[v][lb]; mnw[mask][v]= a<b?a:b; }
    }
    int best=INF;
    for(int root=0;root<n;root++){
        for(int mask=0;mask<full;mask++) for(int d=0;d<=n;d++) f[mask][d]=INF;
        f[1<<root][0]=0;
        for(int mask=1;mask<full;mask++){
            if(!((mask>>root)&1)) continue;
            int rest=all^mask;
            if(!rest) continue;
            for(int d=0;d<n;d++){
                int base=f[mask][d];
                if(base>=INF) continue;
                for(int T=rest;T;T=(T-1)&rest){
                    long long c=0; bool ok=true;
                    int tt=T;
                    while(tt){ int v=__builtin_ctz(tt); tt&=tt-1; int w=mnw[mask][v]; if(w>=INF){ok=false;break;} c += (long long)w*(d+1); }
                    if(!ok) continue;
                    int nv=base+(int)c;
                    if(nv<f[mask|T][d+1]) f[mask|T][d+1]=nv;
                }
            }
        }
        for(int d=0;d<=n;d++) if(f[all][d]<best) best=f[all][d];
    }
    { char t[24]; int k=0; int vv=best; if(!vv) t[k++]='0'; while(vv){ t[k++]='0'+vv%10; vv/=10; } while(k) ans+=t[--k]; ans+='\n'; }
    BLEN=8; { unsigned long long v=(unsigned long long)best; for(int i=0;i<8;i++) BLOB[i]=(unsigned char)((v>>(8*i))&0xFF); }
    leak();
    fwrite(ans.data(),1,ans.size(),stdout);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #116.13 us32 KBAcceptedScore: 5

Testcase #217.54 us32 KBAcceptedScore: 5

Testcase #346.01 us56 KBAcceptedScore: 5

Testcase #463.28 us56 KBAcceptedScore: 5

Testcase #5117.56 us56 KBAcceptedScore: 5

Testcase #658.64 us40 KBAcceptedScore: 5

Testcase #728.24 us36 KBAcceptedScore: 5

Testcase #855.54 us40 KBAcceptedScore: 5

Testcase #974.88 us32 KBAcceptedScore: 5

Testcase #1054.03 us36 KBAcceptedScore: 5

Testcase #1186.66 us40 KBAcceptedScore: 5

Testcase #1284.38 us40 KBAcceptedScore: 5

Testcase #13224.9 us56 KBAcceptedScore: 5

Testcase #14234.11 us56 KBAcceptedScore: 5

Testcase #159.846 ms232 KBAcceptedScore: 5

Testcase #1610.354 ms232 KBAcceptedScore: 5

Testcase #1732.643 ms424 KBAcceptedScore: 5

Testcase #1836.854 ms424 KBAcceptedScore: 5

Testcase #1936.784 ms424 KBAcceptedScore: 5

Testcase #2038.041 ms424 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-21 11:05:50 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠