QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548920 | #6406. Stage Clear | pandapythoner# | TL | 6908ms | 420820kb | C++23 | 3.0kb | 2024-09-05 22:07:59 | 2024-09-05 22:07:59 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define len(a) int((a).size())
#define all(a) begin(a), end(a)
#define rep(i, n) for (int i = 0; i < (n); i++)
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/extc++.h>
struct hash_for_hash_map {
size_t operator()(size_t x) const {
static const size_t D = std::chrono::steady_clock::now().time_since_epoch().count();
return x * x + D;
}
};
template<typename key_t, typename value_t, typename hash_t = hash_for_hash_map>
using hash_map = __gnu_pbds::gp_hash_table<key_t, value_t, hash_t>;
template<typename value_t, typename hash_t = hash_for_hash_map>
using hash_set = __gnu_pbds::gp_hash_table<value_t, __gnu_pbds::null_type, hash_t>;
template<typename key_t, typename value_t, typename comp = std::less<key_t>>
using ordered_map = __gnu_pbds::tree<key_t, value_t,
comp, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template<typename value_t, typename comp = std::less<value_t>>
using ordered_set = ordered_map<value_t, __gnu_pbds::null_type, comp>;
int n, m;
vector<ll> g;
vector<ll> a, b;
// hash_map<ll, ll> mem;
unordered_map<ll, ll> mem;
vector<int> ord;
ll dfs(ll mask) {
if (mask == (1ll << n) - 1) {
return 0;
}
auto it = mem.find(mask);
if (it != mem.end()) {
return it->second;
}
ll adj = 0;
for (int i = 0; i < n; i++) {
if (mask >> i & 1) {
adj |= g[i];
}
}
pair<ll, int> best_pos = { 1e18, -1 };
pair<ll, int> best_neg = { -1e18, -1 };
for (int i = 0; i < n; i++) {
if ((adj >> i & 1) && !(mask >> i & 1)) {
if ((g[i] & mask) != g[i]) continue;
if (a[i] <= b[i]) {
best_pos = min(best_pos, make_pair(a[i], i));
} else {
best_neg = max(best_neg, make_pair(b[i], i));
}
}
}
ll res = 1e18;
// for (int i = 0; i < n; i++) {
for (auto i : ord) {
if ((adj >> i & 1) && !(mask >> i & 1)) {
if ((g[i] & mask) == g[i]) {
if (i != best_pos.second && i != best_neg.second) {
continue;
}
}
if (res <= a[i]) continue;
res = min(res, max(a[i], dfs(mask | (1ll << i)) + a[i] - b[i]));
}
}
return mem[mask] = res;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
mem.rehash(3e6);
cin >> n >> m;
a.resize(n);
b.resize(n);
for (int i = 1; i < n; i++) {
cin >> a[i] >> b[i];
}
g.resize(n);
while (m--) {
int v, u;
cin >> v >> u;
v--, u--;
g[v] |= 1ll << u;
g[u] |= 1ll << v;
}
ord.resize(n);
iota(all(ord), 0);
sort(all(ord), [&](int v, int u) {
return a[v] < a[u];
});
cout << dfs(1) << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 27940kb
input:
4 4 4 2 5 3 2 6 1 2 1 3 2 4 3 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 3ms
memory: 27968kb
input:
15 14 254040392438309 117083115436273 500005748229691 557255157630172 821034233718230 865199673774998 659892147898798 987564141425694 81172575487567 811635577877255 751768357864605 341103322647288 454926350150218 140191090713900 921608121471585 659295670987251 223751724062143 505619245326640 8907765...
output:
1665396301509143
result:
ok 1 number(s): "1665396301509143"
Test #3:
score: 0
Accepted
time: 3ms
memory: 27940kb
input:
18 17 636830992776530 847574431876821 330869946457865 78274534165482 450581372553540 11565219334965 8736347226844 17186323694285 870805093198860 559070167736042 674369178493171 930151818400874 641605209598997 222521062460239 450936030349531 469197172169023 831295459816974 626096008793091 53095460351...
output:
2375957544280218
result:
ok 1 number(s): "2375957544280218"
Test #4:
score: 0
Accepted
time: 0ms
memory: 28004kb
input:
20 19 539893468691183 767805205447882 240338186903141 960937349402327 942645580569365 896509929612645 542601575005817 191461109090531 540992546866047 765080044816119 904535155855114 858111921213175 452499200048240 115895143306864 983856946412026 838504718536099 586421298181479 265212699386882 677124...
output:
800919806038419
result:
ok 1 number(s): "800919806038419"
Test #5:
score: 0
Accepted
time: 0ms
memory: 28064kb
input:
24 23 114281007218527 308690671179962 145951034437731 718976086594208 709172151907814 926071954787084 224496444610281 498657753059525 874422017133378 857676356343078 532175866197017 818525693672607 303837639402605 374469705563954 512244364294540 952911486867703 748959419417502 249992707230361 512696...
output:
114281007218527
result:
ok 1 number(s): "114281007218527"
Test #6:
score: 0
Accepted
time: 897ms
memory: 84928kb
input:
36 35 389328367777319 678636570542258 32216944647452 612585362150577 891592845704885 596030605892036 688825276167602 461516360471825 916552899998310 106733202183953 400050408958777 670724326933521 995792861502757 894514508573875 14511185222713 612305257166443 175168368096281 508263855969282 85578802...
output:
171942144116875
result:
ok 1 number(s): "171942144116875"
Test #7:
score: 0
Accepted
time: 12ms
memory: 29008kb
input:
36 35 759037289890767 849577210686635 16379509883489 441829377955433 589378488455351 990818352083122 871208015900506 727359003875494 207852561142533 28766987248469 81321183353129 892618157632070 198487099788393 519364502513651 83942803274015 988821788304459 868185445880277 269956013388079 3834515054...
output:
759037289890767
result:
ok 1 number(s): "759037289890767"
Test #8:
score: 0
Accepted
time: 11ms
memory: 29176kb
input:
36 35 100792831728257 823656493168793 866936535786311 187861146327778 132998929717538 605906559206892 3319598846477 393401056223733 964444786730964 932398059281618 925176496607384 148825907337833 985037559482190 646827297289525 469876125353024 641923164294854 453796287874442 291205025001534 72806942...
output:
1397699717661157
result:
ok 1 number(s): "1397699717661157"
Test #9:
score: 0
Accepted
time: 425ms
memory: 58824kb
input:
36 36 245996406159980 462974248377488 839352152971124 40282565369163 572695144110271 507726167903341 671102350267895 18090181781241 643724978558334 551787913319524 936340565446887 517649577919257 158127116487034 175750969611510 396852573858996 670814068366285 534702788102341 124550558279140 69441153...
output:
2508008255775889
result:
ok 1 number(s): "2508008255775889"
Test #10:
score: 0
Accepted
time: 101ms
memory: 36044kb
input:
34 38 656738239290510 319959252044415 760511943177376 828562698756504 470087249708484 441916827764162 105399930988058 761192720347117 81742549616394 195819875734286 782982110569406 72384154665629 647269989285797 720280547207448 531182311814386 160821851115134 292963780645658 871789628567253 74499577...
output:
656738239290510
result:
ok 1 number(s): "656738239290510"
Test #11:
score: 0
Accepted
time: 6908ms
memory: 420820kb
input:
32 40 818105834607446 689904077664886 717146597564762 686987602224041 538827104521875 147060924732538 604913134601443 802546720879673 45376965619246 480061093729529 686039951678173 889398415870480 374408509732957 354006189233817 103818950629279 863526642478066 719174876808085 130061851080766 9744074...
output:
2289520618562758
result:
ok 1 number(s): "2289520618562758"
Test #12:
score: -100
Time Limit Exceeded
input:
30 42 730678486091139 762413502107242 564137648972911 492217680357057 677122869459914 634406715345550 766223620461328 750896882727596 34139073751269 875301336250330 948602995486093 589201509496124 333847023521138 673322700954330 774661538057122 360743409997856 301647343463502 78371781314140 44979585...