結果

問題 No.845 最長の切符
ユーザー yuyayuya
提出日時 2019-06-29 12:43:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 3,000 ms
コード長 2,456 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 101,964 KB
実行使用メモリ 11,808 KB
最終ジャッジ日時 2023-09-14 23:11:41
合計ジャッジ時間 2,510 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 13 ms
5,072 KB
testcase_16 AC 51 ms
11,760 KB
testcase_17 AC 12 ms
4,972 KB
testcase_18 AC 25 ms
7,268 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 55 ms
11,716 KB
testcase_21 AC 64 ms
11,728 KB
testcase_22 AC 13 ms
5,012 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 51 ms
11,740 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 36 ms
11,732 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 47 ms
11,808 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:57:49: 警告: overflow in conversion from ‘long long int’ to ‘std::vector<int>::value_type’ {aka ‘int’} changes value from ‘-10000000000’ to ‘-1410065408’ [-Woverflow]
   57 |         vector<vector<int>> d(n, vector<int>(n, -INF));
      |                                                 ^~~~

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define MX 100010


template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
//const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//



constexpr Int INF = 1e10;




int main()
{
        int n, m;
        cin >> n >> m;
        vector<vector<int>> d(n, vector<int>(n, -INF));
        for(int i = 0; i < m; i++)
        {
                int a, b, c;
                cin >> a >> b >> c;
                a--;
                b--;
                chmax(d[a][b], c);
                chmax(d[b][a], c);
        }

        vector<vector<Int>> dp(n, vector<Int>(1<<n, -INF));
        for(int i = 0; i < n; i++)
        {
                dp[i][1<<i] = 0;
        }
        Int ret = 0;
        for(int s = 0; s < (1<<n); s++)
        {
                for(int D = 0; D < n; D++)
                {
                        if((1<<D) & s)
                        {
                                for(int dd = 0; dd < n; dd++)
                                {
                                        if(!((1<<dd) & s) and d[D][dd] > 0)
                                        {
                                                chmax(dp[dd][s ^ (1<<dd)], dp[D][s] + d[D][dd]);
                                                chmax(ret,dp[dd][s ^ (1<<dd)]);
                                        }
                                }
                        }
                }
        }
        cout << ret << endl;
        return 0;
}



















0