QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418378#3745. 排列ZayinCTT#AC ✓526ms9868kbC++111.9kb2024-05-23 13:22:482024-05-23 13:22:49

Judging History

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

  • [2024-05-23 13:22:49]
  • 评测
  • 测评结果:AC
  • 用时:526ms
  • 内存:9868kb
  • [2024-05-23 13:22:48]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
// Your shadow Gets in the way of my light
uint P[25],E[25];
llt Ans[1u<<20|1];
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    uint n,m;
    while(scanf("%u%u",&n,&m)==2&&n)
    {
        for(uint i=0;i<n;i++)scanf("%u",P+i),E[i]=0;
        std::sort(P,P+n);
        while(m--)
        {
            uint u,v;scanf("%u%u",&u,&v),u--,v--;
            E[u]|=1u<<v,E[v]|=1u<<u;
        }
        for(uint i=1;i<(1u<<n);i++)
        {
            Ans[i]=1e18;
            uint r=__builtin_popcount(i);
            for(uint j=0;j<n;j++)if(i>>j&1)
            {
                _min<llt>(Ans[i],Ans[i^(1u<<j)]+(llt)P[r-1]*__builtin_popcount(E[j]&i)
                                                -(llt)P[r-1]*__builtin_popcount(E[j]&~i));
            }
            // printf(":%lld\n",Ans[i]);
        }
        printf("%lld\n",Ans[(1u<<n)-1]);
    }
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 526ms
memory: 9868kb

input:

10 2
840992398 69963455 393388491 672595500 780588893 558816806 9701416 311501224 368780848 930456829
1 6
1 4
10 0
411934118 140341026 198159044 539803943 494456917 558065612 943756089 206990595 183787315 315629195
10 16
162867395 704155151 462516209 378129375 222657670 984933865 265046889 623734262...

output:

81887267
0
2457714684
6401740820
5424851458
3900698784
8717116385
504197343
1452641706
1954315205
3617274900
2180299880
3543452014
14778816638
7499458544
12651888201
7478884769
0
12134304884
1547767459
11362940
16127124432
1439378250
11365774290
4220050883
7009786663
952110870
11437926977
7275268979...

result:

ok 5000 numbers