結果

問題 No.19 ステージの選択
ユーザー btkbtk
提出日時 2015-05-05 02:41:49
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,519 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 112,596 KB
実行使用メモリ 600,060 KB
最終ジャッジ日時 2023-09-19 07:00:26
合計ジャッジ時間 8,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
int N, item[100];
vector<list<int> >adj;
vector<vector<int>> group;
void bfs(int s){
	bool used[100] = { false };
	used[s] = true;
	queue<int>que;
	que.push(s);
	while (que.empty() == false){
		int v = que.front(); que.pop();
		group[s][v / 25] |= (1 << (v % 25));
		for (auto &u : adj[v]){
			if (used[u])continue;
			used[u] = true;
			que.push(u);
		}
	}

}
int main(void){
	map<vector<int>, int> dp;
	vector<int> ans(4, 0);
	dp[ans] = 0;
	int sum = 0;
	cin >> N;
	adj.resize(N);
	group.resize(N);
	for (int i = 0; i < N; i++)
	{
		ans[i / 25] |= (1 << (i % 25));
		int p;
		cin >> item[i] >> p;
		p--;
		sum += item[i];
		adj[p].push_back(i);
		group[i].resize(4);
	}

	
	for (int i = 0; i < N; i++){
		bfs(i);
		map<vector<int>, int> uniq;
		for (auto &now : dp){
			vector<int> tmp(4, 0);
			for (int j = 0; j < 4; j++)tmp[j] = now.first[j] | group[i][j];
			if(uniq.count(tmp)==0)uniq[tmp] = now.second + item[i];
			else uniq[tmp] = min(uniq[tmp],now.second + item[i]);
		}
		for (auto &now : uniq){
			if (dp.count(now.first) == 0)dp[now.first] = now.second;
			else dp[now.first] = min(dp[now.first], now.second);
		}
	}
	cout << dp[ans]+(sum-dp[ans])/2.0 << endl;
	return 0;
}
0