제출 #742510

#제출 시각아이디문제언어결과실행 시간메모리
742510bgnbvnbvBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1112 ms414092 KiB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=1e5+10;
const ll inf=1e8;
const ll mod=1e9+7;
const ll block=320;
ll t,y;
ll dp[maxN];
ll a[maxN];
vector<ll>g[maxN];
vector<pli>vec[maxN];
void brute()
{
    for(int i=1;i<=t;i++) dp[i]=0;
    for(int i=1;i<=y;i++) dp[a[i]]=-inf;
    for(int i=1;i<=t;i++)
    {
        for(auto zz:g[i])
        {
            dp[i]=max(dp[i],dp[zz]+1);
        }
    }
    if(dp[t]>=0) cout << dp[t]<<'\n';
    else cout << -1<<'\n';
}
vector<pli> cc;
ll n;
bool vis[maxN];
void prepare()
{
    for(int i=1;i<=n;i++)
    {
        vec[i].pb({i,0});
        for(auto j:g[i])
        {
            cc.clear();
            ll k=0;
            ll q=0;
            while(cc.size()<block)
            {
                if(k==vec[i].size()&&q==vec[j].size()) break;
                else if(k==vec[i].size())
                {
                    if(vis[vec[j][q].fi]==false)
                    {
                        cc.pb({vec[j][q].fi,vec[j][q].se+1});
                        vis[vec[j][q].fi]=true;
                    }
                    q++;
                }
                else if(q==vec[j].size())
                {
                    if(vis[vec[i][k].fi]==false)
                    {
                        cc.pb({vec[i][k]});
                        vis[vec[i][k].fi]=true;
                    }
                    k++;
                }
                else if(vec[i][k].se>vec[j][q].se+1)
                {
                    if(vis[vec[i][k].fi]==false)
                    {
                        cc.pb({vec[i][k]});
                        vis[vec[i][k].fi]=true;
                    }
                    k++;
                }
                else
                {
                    if(vis[vec[j][q].fi]==false)
                    {
                        cc.pb({vec[j][q].fi,vec[j][q].se+1});
                        vis[vec[j][q].fi]=true;
                    }
                    q++;
                }
            }
            swap(vec[i],cc);
            for(auto zz:vec[i])
            {
                vis[zz.fi]=false;
            }
        }
    }
}
bool valid[maxN];
ll m,q;
void solve()
{
    cin >> n >> m >> q;
    for(int i=1;i<=m;i++)
    {
        ll u,v;
        cin >> u >> v;
        g[v].pb(u);
    }
    for(int i=1;i<=n;i++) valid[i]=true;
    prepare();
    for(int i=1;i<=q;i++)
    {
        cin >> t >> y;
        for(int j=1;j<=y;j++) cin >> a[j];
        if(y>=block) brute();
        else
        {
            for(int j=1;j<=y;j++) valid[a[j]]=false;
            bool ok=true;
            for(auto zz:vec[t])
            {
                if(valid[zz.fi]==true)
                {
                    ok=false;
                    cout << zz.se<<'\n';
                    break;
                }
            }
            if(ok==true)
            {
                cout << -1<<'\n';
            }
            for(int j=1;j<=y;j++) valid[a[j]]=true;
        }
    }
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'void prepare()':
bitaro.cpp:48:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 if(k==vec[i].size()&&q==vec[j].size()) break;
      |                    ~^~~~~~~~~~~~~~~
bitaro.cpp:48:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 if(k==vec[i].size()&&q==vec[j].size()) break;
      |                                      ~^~~~~~~~~~~~~~~
bitaro.cpp:49:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |                 else if(k==vec[i].size())
      |                         ~^~~~~~~~~~~~~~~
bitaro.cpp:58:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                 else if(q==vec[j].size())
      |                         ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...