提出 #73529840


ソースコード 拡げる

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

ll n,m;
vector<ll> v[300030];
ll chk[300030],sum[300030];
vector<ll> order;

void dijkstra()
{
    priority_queue<ll,vector<ll>,greater<ll>> pq;
    chk[1]=1;
    pq.push(1);
    while (!pq.empty())
    {
        ll top=pq.top(); pq.pop();
        order.push_back(top);
        for (auto x : v[top])
        {
            if (chk[x]==0)
            {
                chk[x]=1;
                pq.push(x);
            }
        }
    }
}

int main()
{
    cin>>n>>m;
    set<array<ll,2>> st;
    for (ll i=1;i<=m;i++)
    {
        ll x,y;
        cin>>x>>y;
        if (x==y||st.find({x,y})!=st.end()) continue;
        v[x].push_back(y);
        st.insert({x,y});
    }
    order.push_back(0);
    dijkstra();
    ll siz=order.size()-1;
    for (ll i=1;i<=siz;i++)
    {
        sum[i]=max(sum[i-1],order[i]);
    }
    set<ll> s;
    for (ll i=1;i<=siz;i++)
    {
        if (s.find(i)!=s.end()) s.erase(i);
        for (auto x : v[i])
        {
            if (x>i) s.insert(x);
        }
        if (sum[i]!=i) cout<<"-1\n";
        else
        {
            cout<<s.size()<<"\n";
        }
    }
    for (ll i=siz+1;i<=n;i++) cout<<"-1\n";
}

提出情報

提出日時
問題 F - Reachable Set 2
ユーザ prologue1017
言語 C++23 (GCC 15.2.0)
得点 500
コード長 1281 Byte
結果 AC
実行時間 519 ms
メモリ 46872 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 55
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 3 ms 3604 KiB
example_01.txt AC 3 ms 3672 KiB
hand_00.txt AC 443 ms 45560 KiB
hand_01.txt AC 401 ms 38460 KiB
hand_02.txt AC 425 ms 45484 KiB
hand_03.txt AC 414 ms 45564 KiB
hand_04.txt AC 285 ms 26772 KiB
hand_05.txt AC 362 ms 33900 KiB
hand_06.txt AC 424 ms 45536 KiB
hand_07.txt AC 433 ms 45628 KiB
hand_08.txt AC 8 ms 3652 KiB
hand_09.txt AC 3 ms 3672 KiB
hand_10.txt AC 3 ms 3540 KiB
hand_11.txt AC 62 ms 3516 KiB
hand_12.txt AC 448 ms 44224 KiB
hand_13.txt AC 445 ms 44292 KiB
hand_14.txt AC 447 ms 45580 KiB
hand_15.txt AC 409 ms 45568 KiB
hand_16.txt AC 438 ms 45660 KiB
random_00.txt AC 249 ms 20740 KiB
random_01.txt AC 306 ms 27156 KiB
random_02.txt AC 376 ms 33748 KiB
random_03.txt AC 266 ms 23100 KiB
random_04.txt AC 291 ms 26052 KiB
random_05.txt AC 356 ms 34388 KiB
random_06.txt AC 514 ms 46748 KiB
random_07.txt AC 515 ms 46872 KiB
random_08.txt AC 519 ms 46792 KiB
random_09.txt AC 111 ms 4480 KiB
random_10.txt AC 337 ms 28180 KiB
random_11.txt AC 457 ms 38084 KiB
random_12.txt AC 3 ms 3716 KiB
random_13.txt AC 20 ms 6204 KiB
random_14.txt AC 432 ms 40860 KiB
random_15.txt AC 3 ms 3780 KiB
random_16.txt AC 28 ms 7264 KiB
random_17.txt AC 285 ms 30136 KiB
random_18.txt AC 3 ms 3584 KiB
random_19.txt AC 28 ms 7064 KiB
random_20.txt AC 344 ms 34520 KiB
random_21.txt AC 202 ms 14288 KiB
random_22.txt AC 315 ms 27864 KiB
random_23.txt AC 427 ms 37756 KiB
random_24.txt AC 425 ms 37400 KiB
random_25.txt AC 424 ms 37452 KiB
random_26.txt AC 427 ms 37436 KiB
random_27.txt AC 390 ms 34024 KiB
random_28.txt AC 391 ms 33992 KiB
random_29.txt AC 390 ms 33992 KiB
random_30.txt AC 345 ms 29244 KiB
random_31.txt AC 341 ms 29372 KiB
random_32.txt AC 339 ms 29356 KiB
random_33.txt AC 308 ms 27460 KiB
random_34.txt AC 311 ms 27484 KiB
random_35.txt AC 310 ms 27524 KiB