QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#882991#6406. Stage ClearcyxWA 5280ms3584kbC++143.0kb2025-02-05 14:15:222025-02-05 14:15:23

Judging History

This is the latest submission verdict.

  • [2025-02-05 14:15:23]
  • Judged
  • Verdict: WA
  • Time: 5280ms
  • Memory: 3584kb
  • [2025-02-05 14:15:22]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++
char buf[1000000], *p1 = buf, *p2 = buf;
template <typename T>
void read(T &x)
{
    x = 0;
    int f = 1;
    char c = getchar();
    for (; c < '0' || c > '9'; c = getchar())
        if (c == '-')
            f = -f;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= f;
}
template <typename T, typename... Args>
void read(T &x, Args &...y)
{
    read(x);
    read(y...);
}
template <class T>
void write(T x)
{
    static int stk[30];
    if (x < 0)
        putchar('-'), x = -x;
    int top = 0;
    do
    {
        stk[top++] = x % 10, x /= 10;
    } while (x);
    while (top)
        putchar(stk[--top] + '0');
}
template <class T>
void write(T x, char lastChar) { write(x), putchar(lastChar); }
#define FIO(s)                    \
    freopen(s ".in", "r", stdin); \
    freopen(s ".out", "w", stdout);
template <typename T>
void chkmn(T &x, T y) { x = min(x, y); }
typedef long long ll;
mt19937 rnd(1145141);
int n, m;
ll a[80];
ll b[80];
bitset<80> e[80];
bitset<80> ok;
vector<int> p;
int main()
{
    // FIO("clear");
    read(n, m);
    for (int i = 2; i <= n; i++)
        read(a[i], b[i]);
    while (m--)
    {
        int u, v;
        read(u, v);
        e[u][v] = 1;
    }
    auto dfs = [&](auto self, int u) -> void
    {
        ok[u] = 1;
        if (u != 1)
            p.emplace_back(u);
        for (int v = 1; v <= n; v++)
        {
            if (e[u][v] && !ok[v])
                self(self, v);
        }
    };
    dfs(dfs, 1);
    int T = 40000000;
    ll ans = 1e18;
    while (T--)
    {
        vector<array<int, 2>> vec;
        for (int i = 0; i < (T >= 3e7 ? 9 : T >= 2e7 ? 6
                                                     : 4);
             i++)
        {
            int x = rnd() % p.size();
            int y = rnd() % p.size();
            vec.push_back({x, y});
            swap(p[x], p[y]);
        }
        int t = 0;
        ll w = 0;
        ll mn = 0;
        int lst = 1;
        bool flag = 0;
        ok.reset();
        ok |= e[1];
        for (int i : p)
        {
            if (!ok[i])
            {
                flag = 1;
                break;
            }
            if (lst == 1)
            {
                lst = i;
                w = b[i] - a[i];
                chkmn(mn, -a[i]);
                chkmn(mn, w);
            }
            else
            {
                lst = i;
                chkmn(mn, w - a[i]);
                w += b[i] - a[i];
                chkmn(mn, w);
            }
            ok |= e[i];
        }
        if (!flag && -mn < ans)
        {
            ans = -mn;
        }
        else
        {
            reverse(vec.begin(), vec.end());
            for (auto [x, y] : vec)
                swap(p[x], p[y]);
        }
    }
    write(ans, '\n');
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4807ms
memory: 3584kb

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: 5132ms
memory: 3584kb

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: 5190ms
memory: 3456kb

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: 5218ms
memory: 3584kb

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: 5161ms
memory: 3456kb

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
Wrong Answer
time: 5280ms
memory: 3584kb

input:

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

output:

389328367777319

result:

wrong answer 1st numbers differ - expected: '171942144116875', found: '389328367777319'