結果

問題 No.2999 Long Long Friedrice
ユーザー t98slider
提出日時 2025-01-19 21:21:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 3,708 ms
コンパイル使用メモリ 204,960 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2025-01-19 21:22:01
合計ジャッジ時間 4,507 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

struct csr {
    using itr = std::vector<int>::iterator;
    struct Node {
        itr st, en;
        itr begin() { return st; }
        itr end() { return en; }
    };
    const int N;
    std::vector<int> start, E;
    std::vector<std::pair<int,int>> edge;
    csr(int n) : N(n), start(n + 1) {}
    void add_edge(int u, int v){
        assert(0 <= u && u < N);
        start[u + 1]++;
        edge.emplace_back(u, v);
    }
    void build(){
        E.resize(edge.size());
        for(int i = 0; i < N; i++) start[i + 1] += start[i];
        auto cnt = start;
        for(auto [u, v] : edge) E[cnt[u]++] = v;
    }
    Node operator[](int p) {
        return Node{E.begin() + start[p], E.begin() + start[p + 1]};
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    cin >> a >> b;
    csr g(500001);
    vector<bool> used(500001);
    for(int i = 0; i < n; i++){
        g.add_edge(a[i], a[i] + b[i]);
    }
    g.build();
    queue<int> que;
    que.emplace(1);
    int ans = 1;
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto &&u : g[v]){
            ans = max(ans, u);
            if(u <= 500000 && !used[u]){
                used[u] = true;
                que.emplace(u);
            }
        }
    }
    cout << ans << '\n';
}
0