結果

問題 No.417 チューリップバブル
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-06-29 10:03:55
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,161 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 69,680 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 07:18:56
合計ジャッジ時間 4,171 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 47 ms
5,376 KB
testcase_12 AC 46 ms
5,376 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 77 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 7 ms
5,376 KB
testcase_17 AC 40 ms
5,376 KB
testcase_18 AC 41 ms
5,376 KB
testcase_19 AC 40 ms
5,376 KB
testcase_20 AC 156 ms
5,376 KB
testcase_21 AC 157 ms
5,376 KB
testcase_22 AC 156 ms
5,376 KB
testcase_23 AC 156 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 158 ms
5,376 KB
testcase_26 AC 15 ms
5,376 KB
testcase_27 AC 110 ms
5,376 KB
testcase_28 AC 154 ms
5,376 KB
testcase_29 AC 156 ms
5,376 KB
testcase_30 AC 158 ms
5,376 KB
testcase_31 AC 155 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 33 ms
5,376 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
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",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |                 scanf("%d",&taxes[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~
main.cpp:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |                 scanf("%d %d %d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

//このコードを模範解答としてください。
#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<string.h>

const int LIMITM=2001;
const int LIMITN=100;
int dp[LIMITN][LIMITM];
std::map<int,int> tree[LIMITN];
int taxes[LIMITN];
int n,m;
void f(int oya,int now){
	memset(dp[now],0,sizeof(dp[now]));
	std::map<int,int>::iterator it;
	for(it=tree[now].begin();it!=tree[now].end();it++){
		int next=(*it).first;
		int time=(*it).second*2;
		if(oya==next){
			continue;
		}
		f(now,next);
		int temp[LIMITM];
		memcpy(temp,dp[now],sizeof(dp[now]));
		for(int i=0;i+time<=m;i++){
			for(int j=0;j+i+time<=m;j++){
				int nextTime=j+i+time;
				int nextTax=dp[now][i]+dp[next][j];
				temp[nextTime]=std::max(temp[nextTime],nextTax);
			}
		}
		memcpy(dp[now],temp,sizeof(temp));
	}
	for(int i=0;i<=m;i++){
		dp[now][i]+=taxes[now];
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&taxes[i]);
	}
	for(int i=0;i<n-1;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		tree[a][b]=c;
		tree[b][a]=c;
	}
	f(-1,0);
	int ans=0;
	for(int i=0;i<=m;i++){
		ans=std::max(ans,dp[0][i]);
	}
	printf("%d\n",ans);
}
0