QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106881#6406. Stage Clearwhatever#WA 2ms3632kbC++171.1kb2023-05-19 17:07:412023-05-19 17:07:43

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:07:43]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3632kb
  • [2023-05-19 17:07:41]
  • 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<ll, ll> mp;

inline bool ck(int u, int v)
{
    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(S)) return mp[S];
    ll res = 1e18;
    for (int u = 1; u <= n; u++) if (T >> u & 1)
    {
        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);
        }
    }
    return mp[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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

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: -100
Wrong Answer
time: 2ms
memory: 3632kb

input:

15 14
254040392438309 117083115436273
500005748229691 557255157630172
821034233718230 865199673774998
659892147898798 987564141425694
81172575487567 811635577877255
751768357864605 341103322647288
454926350150218 140191090713900
921608121471585 659295670987251
223751724062143 505619245326640
8907765...

output:

2075075173063762

result:

wrong answer 1st numbers differ - expected: '1665396301509143', found: '2075075173063762'