結果

問題 No.90 品物の並び替え
コンテスト
ユーザー tkzw_21
提出日時 2014-12-07 19:21:42
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 282 ms / 5,000 ms
コード長 671 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,325 ms
コンパイル使用メモリ 170,872 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:00:01
合計ジャッジ時間 2,180 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:25: warning: ‘i2’ may be used uninitialized [-Wmaybe-uninitialized]
   31 |                         if(i1 < i2)ans += score[i];
      |                         ^~
main.cpp:26:32: note: ‘i2’ was declared here
   26 |                         int i1,i2;
      |                                ^~
main.cpp:31:25: warning: ‘i1’ may be used uninitialized [-Wmaybe-uninitialized]
   31 |                         if(i1 < i2)ans += score[i];
      |                         ^~
main.cpp:26:29: note: ‘i1’ was declared here
   26 |                         int i1,i2;
      |                             ^~

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
	int n,m;
	cin >> n >> m;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		v[i] = i;
	}
	vector<int> item1(m),item2(m),score(m);
	for(int i=0;i<m;i++){
		cin >> item1[i] >> item2[i] >> score[i];
	}

	int ret = 0;
	do{
		int ans = 0;
		for(int i=0;i<m;i++){
			int i1,i2;
			for(int j=0;j<n;j++){
				if(item1[i] == v[j])i1 = j;
				if(item2[i] == v[j])i2 = j;
			}
			if(i1 < i2)ans += score[i];
		}
		ret = max(ret,ans);
	}while(next_permutation(v.begin(),v.end()));
	cout << ret << endl;

}
0