結果

問題 No.90 品物の並び替え
ユーザー Yang33Yang33
提出日時 2018-05-05 01:54:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 963 bytes
コンパイル時間 1,853 ms
コンパイル使用メモリ 174,448 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 10:04:09
合計ジャッジ時間 2,717 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 11 ms
4,376 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 93 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    
    using VS = vector<string>;    using LL = long long;
    using VI = vector<int>;       using VVI = vector<VI>;
    #define ALL(a)  begin((a)),end((a))
    #define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
    
    LL ans = 0LL;
    
    int main() {
    	cin.tie(0);
    	ios_base::sync_with_stdio(false);
    
    	int N, M; cin >> N >> M;
    	using tp = tuple<int, int, int>;
    	vector<tp>rules(M);
    	FOR(i, 0, M) {
    		int a, b, c; cin >> a >> b >> c;
    		rules[i] = tp(a, b, c);
    	}
    
    	VI a(N, 0);
    	iota(ALL(a), 0);
    
    	do {
    		LL ret = 0;
			VI b(N);
			FOR(j, 0, N) {
				b[a[j]] = j;
			}
    		for (tp& rule : rules) {

    			int x, y, z; tie(x, y, z) = rule;
    			if (b[x] < b[y]) {
    				ret += z;
    			}
    		}
    
    		ans = max(ans, ret);
    	} while (next_permutation(ALL(a)));
    
    	cout << ans << "\n";
    
    	return 0;
    }
0