QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883049 | #6406. Stage Clear | gty314159 | RE | 5864ms | 316996kb | C++17 | 2.0kb | 2025-02-05 14:32:50 | 2025-02-05 14:32:55 |
Judging History
answer
#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
const int P = 900001;
const int M = 2e7 + 5;
const LL inf = 1e18;
int n, m; LL a[40], b[40], out[40];
int nxtt[M]; LL idd[M], vall[M], bit[40];
struct Hash {
int tot, head[P], *nxt; LL *id, *val;
void Insert(LL x) {
int u = x % P;
for (int i = head[u]; i; i = nxt[i])
if (id[i] == x) return ;
id[++tot] = x, val[tot] = inf;
nxt[tot] = head[u], head[u] = tot;
}
LL Query(LL x) {
for (int i = head[x % P]; i; i = nxt[i])
if (id[i] == x) return val[i];
}
} f[36];
int main() {
// freopen("clear.in", "r", stdin);
// freopen("clear.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
F(i, 1, n) bit[i] = 1ll << i - 1;
F(i, 2, n) cin >> a[i] >> b[i];
F(i, 1, m) { int u, v; cin >> u >> v, out[u] |= bit[v]; }
f[n - 1].nxt = nxtt, f[n - 1].id = idd, f[n - 1].val = vall;
f[n - 1].Insert((1ll << n) - 2);
dF(i, n - 2, 0) {
f[i].nxt = f[i + 1].nxt + f[i + 1].tot + 1;
f[i].id = f[i + 1].id + f[i + 1].tot + 1;
f[i].val = f[i + 1].val + f[i + 1].tot + 1;
F(j, 1, f[i + 1].tot) {
LL st = f[i + 1].id[j], nxt = 0;
F(k, 1, n) if (!(st & bit[k])) nxt |= out[k];
F(k, 1, n) if ((nxt & bit[k]) && (st & bit[k]))
f[i].Insert(st ^ bit[k]);
}
}
f[0].val[1] = 0;
F(i, 0, n - 2) {
F(j, 1, f[i + 1].tot) {
LL st = f[i + 1].id[j], nxt = 0;
F(k, 1, n) if (!(st & bit[k])) nxt |= out[k];
F(k, 1, n) if ((nxt & bit[k]) && (st & bit[k])) {
LL dp = f[i].Query(st ^ bit[k]);
f[i + 1].val[j] = min(f[i + 1].val[j], a[k] + max(dp - b[k], 0ll));
}
}
}
cout << f[n - 1].val[1] << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12008kb
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: 0ms
memory: 12524kb
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: 0ms
memory: 16616kb
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: 17508kb
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: 2ms
memory: 27756kb
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: 5864ms
memory: 316996kb
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: 2658ms
memory: 199240kb
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: 50ms
memory: 81692kb
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: -100
Runtime Error
input:
36 36 245996406159980 462974248377488 839352152971124 40282565369163 572695144110271 507726167903341 671102350267895 18090181781241 643724978558334 551787913319524 936340565446887 517649577919257 158127116487034 175750969611510 396852573858996 670814068366285 534702788102341 124550558279140 69441153...