제출 #1160351

#제출 시각아이디문제언어결과실행 시간메모리
1160351hainam2k9Bitaro’s Party (JOI18_bitaro)C++20
100 / 100
1032 ms411420 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,m,q,t,x,y,dist[MAXN],a[MAXN];
vector<int> adj[MAXN];
vector<pair<int,int>> v[MAXN];
bool vis[MAXN];
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> m >> q;
    for(int i = 1; i<=m; ++i)
        cin >> x >> y, adj[x].pb(y);
    for(int i = 1; i<=n; ++i){
        v[i].pb(0,i);
        for(int& j : adj[i]){
            vector<pair<int,int>> tmp;
            for(int ptr1=0, ptr2=0; sz(tmp)<300&&(ptr1<sz(v[i])||ptr2<sz(v[j])); ){
                if(ptr1>=sz(v[i])){
                    pair<int,int> p=v[j][ptr2];
                    if(!vis[p.se]) tmp.pb(p), vis[p.se]=1;
                    ++ptr2;
                }
                else if(ptr2>=sz(v[j])){
                    pair<int,int> p=v[i][ptr1];
                    ++p.fi;
                    if(!vis[p.se]) tmp.pb(p), vis[p.se]=1;
                    ++ptr1;
                }else{
                    pair<int,int> p1=v[i][ptr1], p2=v[j][ptr2];
                    ++p1.fi;
                    if(p1.fi>=p2.fi){
                        if(!vis[p1.se]) tmp.pb(p1), vis[p1.se]=1;
                        ++ptr1;
                    }else{
                        if(!vis[p2.se]) tmp.pb(p2), vis[p2.se]=1;
                        ++ptr2;
                    }
                }
            }
            swap(v[j],tmp);
            for(pair<int,int>& p : v[j])
                vis[p.se]=0;
        }
    }
    while(q--){
        cin >> t >> y;
        for(int i = 1; i<=y; ++i)
            cin >> a[i], vis[a[i]]=1;
        if(y<300){
            int rs=-1;
            for(pair<int,int>& p : v[t])
                if(!vis[p.se]){
                    rs=p.fi;
                    break;
                }
            cout << rs << "\n";
        }
        else{
            fill(dist+1,dist+t+1,-1);
            for(int i = 1; i<=t; ++i){
                if(vis[i]&&dist[i]==-1) continue;
                dist[i]=max(dist[i],0);
                for(int& j : adj[i])
                    dist[j]=max(dist[j],dist[i]+1);
            }
            cout << dist[t] << "\n";
        }
        for(int i = 1; i<=y; ++i)
            vis[a[i]]=0;
    }
}
//5 5 1
//1 2
//2 4
//4 5
//1 3
//3 5
//5 3 1 2 4

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

bitaro.cpp: In function 'int main()':
bitaro.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:29:45: note: in expansion of macro 'fo'
   29 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
bitaro.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:29:45: note: in expansion of macro 'fo'
   29 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...