結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-06-29 14:00:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,715 bytes |
| コンパイル時間 | 506 ms |
| コンパイル使用メモリ | 70,076 KB |
| 実行使用メモリ | 9,728 KB |
| 最終ジャッジ日時 | 2024-07-02 05:32:00 |
| 合計ジャッジ時間 | 1,761 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:40:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%d%d%d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
ll dp[1<<16][16];
int main(int argc, char* argv[])
{
int n,m;
scanf("%d%d", &n, &m);
int g[16][16]={0};
int i,j;
for(i=0; i<16; i++) {
for(j=0; j<16; j++) {
g[i][j]=INF;
}
}
for(i=0; i<m; i++) {
int a,b,c;
scanf("%d%d%d", &a, &b, &c);
g[a-1][b-1]=c;
g[b-1][a-1]=c;
}
int k;
for(i=1; i<(1<<n); i++) {
for(k=0; k<n; k++) {
dp[i][k] = INF;
}
}
for(i=1; i<(1<<n); i++) {
for(k=0; k<n; k++) {
if(i & (1<<k)) {
int prev = (i & ~(1<<k));
if(prev==0) {
dp[i][k] = 0;
}
else {
int j;
for(j=0; j<n; j++) {
if(dp[prev][j]!=INF && g[j][k]!=INF) {
dp[i][k] = MIN(dp[i][k], dp[prev][j] + g[j][k]);
}
}
}
}
}
}
ll ans=0;
for(i=1; i<(1<<n); i++) {
for(k=0; k<n; k++) {
if(dp[i][k]!=INF) {
ans = MAX(ans, dp[i][k]);
}
}
}
printf("%lld\n", ans);
return 0;
}
tarattata1