QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106893#6406. Stage Clearwhatever#TL 4ms4252kbC++171.4kb2023-05-19 17:41:522023-05-19 17:42:01

Judging History

This is the latest submission verdict.

  • [2024-08-15 21:05:17]
  • hack成功,自动添加数据
  • (/hack/778)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-19 17:42:01]
  • Judged
  • Verdict: TL
  • Time: 4ms
  • Memory: 4252kb
  • [2023-05-19 17:41:52]
  • Submitted

answer


#include <bits/stdc++.h>

using namespace std; const int maxn = 80; typedef long long ll;

int n, m;

ll a[maxn], b[maxn];

ll G[maxn];

map<pair<int, ll>, ll> mp;

inline bool ck(int u, int v)
{
    // return 1;
    if ((a[u] - b[u] < 0) != (a[v] - b[v] < 0))
        return (a[u] - b[u] < 0) > (a[v] - b[v] < 0);
    if (a[u] - b[u] < 0) return a[u] < a[v]; return b[u] > b[v];
}

ll dfs(ll S, ll T, int lst)
{
    T &= ~S;
    if (T == 0) return 0;
    if (mp.count({ lst, S })) return mp[{ lst, S }];
    ll res = 1e18;
    ll y = T;
    // for (int u = 1; u <= n; u++) if (T >> u & 1)
    while (y)
    {
        int u = __builtin_ctzll(y);
        y ^= 1ull << u;
        if (!lst || ck(lst, u) || (G[lst] >> u & 1))
        {
            ll tmp = dfs(S | (1ull << u), T | G[u], u);
            if (tmp >= b[u]) tmp += a[u] - b[u]; else tmp = a[u];
            res = min(res, tmp);
        }
    }
    // for (int i = 1; i <= n; i++) cerr << (S >> i & 1); cerr << ' ';
    // for (int i = 1; i <= n; i++) cerr << (T >> i & 1); cerr << ' ';
    // cerr << res << endl;
    return mp[{ lst, S }] = res;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 2; i <= n; i++) scanf("%lld%lld", a + i, b + i);
    for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), G[u] |= 1ull << v;
    printf("%lld\n", dfs(0, 1 << 1, 0));
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3468kb

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: 3604kb

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: 4044kb

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: 3952kb

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: 4ms
memory: 4252kb

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: -100
Time Limit Exceeded

input:

36 35
389328367777319 678636570542258
32216944647452 612585362150577
891592845704885 596030605892036
688825276167602 461516360471825
916552899998310 106733202183953
400050408958777 670724326933521
995792861502757 894514508573875
14511185222713 612305257166443
175168368096281 508263855969282
85578802...

output:


result: