QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209000#7558. Abstractucup-team197Compile Error//C++142.5kb2023-10-10 00:20:242023-10-10 00:20:25

Judging History

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

  • [2023-10-10 00:20:25]
  • 评测
  • [2023-10-10 00:20:24]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <array>
#include <numeric>
#include <queue>

using namespace std;
typedef long long ll;

struct BigInt{
    static constexpr ll DIGITS = 30;
    static constexpr ll BASE = 1 << DIGITS;
    vector<ll> digits;
    BigInt(){}
    BigInt(int x){
        digits = {x};
    }

    friend BigInt operator+(const BigInt &l, const BigInt &r){
        BigInt result;
        result.digits.clear();

        ll carry = 0;
        for(int i = 0; i < max(l.digits.size(), r.digits.size()); ++i){
            ll a = 0, b = 0;
            if(i < l.digits.size()) a = l.digits[i];
            if(i < r.digits.size()) b = r.digits[i];

            carry += a + b;
            result.digits.push_back(carry % BASE);
            carry /= BASE;
        }
        if(carry){
            result.digits.push_back(carry);
        }
        return result;
    }

    int count_digits(){
        assert(!digits.empty());

        int count = (int)(digits.size()) - 1;
        count *= DIGITS;

        if(digits.back() == 0){
            return 0;
        }

        ll leading_digit = digits.back();
        while(leading_digit){
            leading_digit /= 2;
            ++count;
        }
        return count;
    }
};

const int N = 1e4 + 3;
const int M = 1e5 + 3;

int n, m, leaf;
int a[N];
vector<int> adj[N];

BigInt dp[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        dp[i] = BigInt(a[i]);
    }
    for(int i = 1; i <= m; ++i){
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
    }

    for(int i = 1; i <= n; ++i){
        if(adj[i].empty()){
            leaf = i;
        }
    }

    static int cnt_pointing[N];
    for(int i = 1; i <= n; ++i){
        for(int to: adj[i]){
            ++cnt_pointing[to];
        }
    }

    queue<int> q;
    for(int i = 1; i <= n; ++i)
        if(!cnt_pointing[i]){
            q.push(i);
        }

    while(!q.empty()){
        int u = q.front();
        q.pop();

        // cout << u << " u" << endl; 

        for(int to: adj[u]){
            dp[to] = dp[to] + dp[u] + dp[u];
            --cnt_pointing[to];
            if(!cnt_pointing[to]){
                q.push(to);
            }
        }
    }

    cout << dp[leaf].count_digits() << "\n";
}

詳細信息

answer.code: In member function ‘int BigInt::count_digits()’:
answer.code:42:9: error: ‘assert’ was not declared in this scope
   42 |         assert(!digits.empty());
      |         ^~~~~~
answer.code:8:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
    7 | #include <queue>
  +++ |+#include <cassert>
    8 |