QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205892#7558. Abstractucup-team052#WA 1ms4116kbC++142.8kb2023-10-07 17:45:322023-10-07 17:45:34

Judging History

你现在查看的是最新测评结果

  • [2023-10-07 17:45:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4116kb
  • [2023-10-07 17:45:32]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 1e4 + 5;

struct bigint { vector <ull> a; };

bigint operator + (bigint a, bigint b) {
    if (a.a.size() < b.a.size()) a.a.resize(b.a.size());
    int jw = 0;
    for (int i = 0; i < (int)a.a.size(); i++) {
        ull tmp = a.a[i];
        int njw = 0;
        if (jw && b.a[i] + jw == 0) njw = 1;
        a.a[i] += (b.a[i] + jw);
        if (a.a[i] < tmp) njw = 1;
        jw = njw;
    }
    if (jw) a.a.push_back(1);
    return a;
}

bigint operator - (bigint a, int b) {
    if (a.a[0] >= (ull)b) {
        a.a[0] -= b;
    } else {
        a.a[0] -= b;
        for (int i = 1; ; i++) {
            if (a.a[i]) {
                --a.a[i];
                break;
            }
        }
    }
    if (a.a.size() && !a.a.back()) a.a.pop_back();
    return a;
}

vector <int> adj[N];
bigint a[N];
queue <int> q;
int id[N], deg[N];
int n, m, len;

int main() {
    read(n); read(m);
    for (int i = 1; i <= n; i++) {
        int x;
        read(x);
        a[i].a.push_back(x);
    }
    for (int i = 1; i <= m; i++) {
        int u, v;
        read(u); read(v);
        adj[u].push_back(v);
        ++deg[v];
    }
    for (int i = 1; i <= n; i++) {
        if (!deg[i]) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int u = q.front(); q.pop();
        id[++len] = u;
        for (auto v : adj[u]) {
            --deg[v];
            if (!deg[v]) q.push(v);
        }
    }
    for (int _ = 1; _ < n; _++) {
        int u = id[_];
        int popc = 0;
        for (int i = 0; i < (int)a[u].a.size(); i++) popc += __builtin_popcountll(a[u].a[i]);
        a[u] = a[u] + a[u];
        a[u] = a[u] - popc;
        for (auto v : adj[u]) {
            a[v] = a[u] + a[v];
        }
    }
    if (!a[id[n]].a.size()) {
        print(0, '\n');
        return 0;
    }
    int ans = ((int)a[id[n]].a.size() - 1) * 64;
    for (int i = 63; i >= 0; i--) {
        if (a[id[n]].a.back() >> i) {
            ans += (i + 1);
            break;
        }
    }
    print(ans, '\n');
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4116kb

input:

3 2
1 1 1
1 2
2 3

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 4044kb

input:

6 8
1 1 4 5 1 4
1 4
1 5
2 3
2 5
3 4
4 5
4 6
5 6

output:

7

result:

wrong answer 1st numbers differ - expected: '8', found: '7'