結果

問題 No.357 品物の並び替え (Middle)
ユーザー naimonon77naimonon77
提出日時 2016-09-25 13:14:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
OLE  
(最初)
実行時間 -
コード長 1,433 bytes
コンパイル時間 1,428 ms
コンパイル使用メモリ 173,412 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2024-04-29 09:22:58
合計ジャッジ時間 11,443 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
6,820 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 99 ms
5,376 KB
testcase_03 AC 97 ms
5,376 KB
testcase_04 AC 395 ms
5,376 KB
testcase_05 AC 397 ms
5,376 KB
testcase_06 AC 29 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1,608 ms
5,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int N, M;
vector<pair<int, int>> a[15];
int dp[1 << 16];

void print() {
	rep(i, 1 << N) {
		string s;
		rep(j, N) {
			if ((i >> j) & 1) s.push_back('1');
			else s.push_back('0');
		}
		reverse(ALL(s));
		cerr << "dp[" << s << "]= " << dp[i] << endl;
	}
}

signed main() {
	cin >> N >> M;
	rep(i, M) {
		int item1, item2, score;
		cin >> item1 >> item2 >> score;
		a[item2].push_back({ item1,score });
	}
	rep(mask, 1 << N) {
		rep(i, N) {
			if (mask & (1 << i)) continue;

			int next_mask = mask | (1 << i);
			if (mask == next_mask) cerr << "error!" << endl;
			int tmp = dp[mask];
			rep(j, a[i].size()) {
				if (mask & (1 << a[i][j].first)) {
					tmp += a[i][j].second;
				}
			}
			if (tmp > dp[next_mask]) dp[next_mask] = tmp;
		}
		dump(mask);
		print();
		cerr << endl;
	}

	cout << dp[(1 << N) - 1] << endl;
	return 0;
}
0