Submission #74858


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/extc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a, b) (((a) + (b) - 1) / (b))
using pii = pair<int,int>;
constexpr int32_t INF = 0x3f3f3f3f;
constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;
template <class Func>
class FixPoint : Func {
public:
explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
template <class... Args>
constexpr decltype(auto) operator()(Args&&... args) const {
return Func::operator()(*this, std::forward<Args>(args)...);
}
};
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
return FixPoint<Func>{forward<Func>(f)};
}
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p){ is >> p.first >> p.second; return (is); }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p){ os << p.first << ' ' << p.second; return (os); }
template<class T> istream& operator>>(istream& is, vector<T>& v){ for (auto &&e : v) is >> e; return (is); }
template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for (auto &&e : v) os << e << ' '; return (os); }
template<class T> inline const T& max(const vector<T> &v) { return *max_element(v.begin(), v.end()); }
template<class T> inline const T& min(const vector<T> &v) { return *min_element(v.begin(), v.end()); }
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class A, class B> using umap = unordered_map<A, B>;
template <class T> using uset = unordered_set<T>;
template <class T> using Max_Heap = __gnu_pbds::priority_queue<T, less<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Min_Heap = __gnu_pbds::priority_queue<T, greater<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class K, class V> using Umap = __gnu_pbds::gp_hash_table<K, V>;
template <class T> using Rope = __gnu_cxx::rope<T>;
using Trie = __gnu_pbds::trie<string, __gnu_pbds::null_type, __gnu_pbds::trie_string_access_traits<>, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_prefix_search_node_update>;
template <class T> void bye(T x){ cout << x << '\n'; exit(0); }
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
signed main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout.setf(ios_base::fixed);
cout.precision(12);
int n, p;
cin >> n >> p;
vector<vector<int> > cost(n, vector<int>(n, INF));
for (int i = 1; i < n; ++i) {
int c, k;
cin >> c >> k;
for (int j = 0; j < k; ++j) {
int s;
cin >> s;
chmin(cost[s - 1][i], c);
}
}
vector<long long> dp(1 << n, LINF);
dp[1 << 0] = 0;
for (int mask = 1; mask < 1 << n; ++mask) {
for (int i = 0; i < n; ++i) {
if (mask >> i & 1) {
for (int j = 0; j < n; ++j) {
chmin(dp[mask | 1 << j], dp[mask] + cost[i][j]);
}
}
}
}
int res = 0;
for (int mask = 1; mask < 1 << n; ++mask) {
if (dp[mask] <= p) {
chmax(res, __builtin_popcount(mask));
}
}
cout << res << '\n';
return (0);
}

ステータス

項目 データ
問題 1510 - Skill Tree
ユーザー名 ei1903
投稿日時 2023-07-25 19:55:46
言語 C++17
状態 Accepted
得点 3
ソースコード長 3908 Byte
最大実行時間 64 ms
最大メモリ使用量 956 KB

セット

セット 得点 Cases
1 ALL 3 / 3 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 64 ms 604 KB
1
in02.txt AC 24 ms 556 KB
1
in03.txt AC 21 ms 608 KB
1
in04.txt AC 20 ms 564 KB
1
in05.txt AC 22 ms 644 KB
1
in06.txt AC 30 ms 592 KB
1
in07.txt AC 25 ms 640 KB
1
in08.txt AC 22 ms 688 KB
1
in09.txt AC 19 ms 612 KB
1
in10.txt AC 21 ms 664 KB
1
in11.txt AC 23 ms 584 KB
1
in12.txt AC 20 ms 756 KB
1
in13.txt AC 27 ms 808 KB
1
in14.txt AC 22 ms 732 KB
1
in15.txt AC 22 ms 656 KB
1
in16.txt AC 19 ms 824 KB
1
in17.txt AC 19 ms 616 KB
1
in18.txt AC 22 ms 664 KB
1
in19.txt AC 19 ms 708 KB
1
in20.txt AC 21 ms 624 KB
1
in21.txt AC 26 ms 804 KB
1
in22.txt AC 17 ms 848 KB
1
in23.txt AC 24 ms 768 KB
1
in24.txt AC 19 ms 688 KB
1
in25.txt AC 21 ms 860 KB
1
in26.txt AC 20 ms 776 KB
1
in27.txt AC 25 ms 692 KB
1
in28.txt AC 22 ms 744 KB
1
in29.txt AC 24 ms 788 KB
1
in30.txt AC 23 ms 840 KB
1
in31.txt AC 27 ms 884 KB
1
in32.txt AC 23 ms 804 KB
1
in33.txt AC 20 ms 720 KB
1
in34.txt AC 18 ms 800 KB
1
in35.txt AC 24 ms 624 KB
1
in36.txt AC 16 ms 956 KB
1
in37.txt AC 27 ms 908 KB
1
sample01.txt AC 23 ms 728 KB
1
sample02.txt AC 30 ms 940 KB
1