답안 #647555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647555 2022-10-03T07:17:00 Z ToroTN Cities (BOI16_cities) C++14
14 / 100
6000 ms 43820 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define X first
#define Y second
ll n,k,m,node[5],u_i,v_i,w_i,d[32][100005],u,num,dp[32],pow_2[5],mn=1e18;
vector<pair<ll,ll> > g[100005];
vector<ll> bit[6];
priority_queue<pair<ll,ll> > pq;
void dij(ll arr[])
{
    for(int i=1;i<=n;i++)
    {
        pq.push({-arr[i],i});
    }
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        for(auto [y,cost]:g[u])
        {
            if(arr[u]+cost<arr[y])
            {
                arr[y]=arr[u]+cost;
                pq.push({-arr[y],y});
            }
        }
    }
}
int main()
{
    pow_2[0]=1;
    for(int i=1;i<=4;i++)
    {
        pow_2[i]=pow_2[i-1]*2;
    }
    scanf("%lld%lld%lld",&n,&num,&m);
    for(int i=1;i<=num;i++)
    {
        scanf("%lld",&node[i-1]);
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%lld%lld%lld",&u_i,&v_i,&w_i);
        g[u_i].pb({v_i,w_i});
        g[v_i].pb({u_i,w_i});
    }
    for(int i=0;i<32;i++)
    {
        for(int j=1;j<=n;j++)
        {
            d[i][j]=1e18;
        }
    }
    for(int i=0;i<num;i++)
    {
        d[pow_2[i]][node[i]]=0;
        dij(d[pow_2[i]]);
    }
    for(int i=0;i<32;i++)
    {
        ll kmp=0;
        for(int j=0;j<=4;j++)
        {
            if((i|pow_2[j])==i)++kmp;
        }
        bit[kmp].pb(i);
    }
    // for(int i=1;i<=n;i++)
    // {
    //     printf("%lld ",d[1][i]);
    // }
    // printf("\n");
    for(int i=2;i<=num;i++)
    {
        for(int j=1;j<=i/2;j++)
        {
            for(auto k:bit[i-j])
            {
                for(auto l:bit[j])
                {
                    if(k!=l)
                    {
                        for(int c=1;c<=n;c++)
                        {
                            d[(k|l)][c]=d[k][c]+d[l][c];
                        }
                        dij(d[(k|l)]);
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        mn=min(mn,d[pow_2[num]-1][i]);
    }

    printf("%lld\n",mn);
}

Compilation message

cities.cpp: In function 'void dij(long long int*)':
cities.cpp:21:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |         for(auto [y,cost]:g[u])
      |                  ^
cities.cpp: In function 'int main()':
cities.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%lld%lld%lld",&n,&num,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%lld",&node[i-1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
cities.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%lld%lld%lld",&u_i,&v_i,&w_i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Incorrect 2 ms 2792 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4003 ms 43744 KB Output is correct
2 Correct 4205 ms 42804 KB Output is correct
3 Correct 2649 ms 35808 KB Output is correct
4 Correct 173 ms 13392 KB Output is correct
5 Correct 936 ms 43768 KB Output is correct
6 Correct 88 ms 13240 KB Output is correct
7 Correct 16 ms 3284 KB Output is correct
8 Correct 5 ms 3188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 3284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6095 ms 43820 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6032 ms 43752 KB Time limit exceeded
2 Halted 0 ms 0 KB -