제출 #1103232

#제출 시각아이디문제언어결과실행 시간메모리
1103232hiensumiBitaro’s Party (JOI18_bitaro)C++14
14 / 100
1159 ms367104 KiB
#include <bits/stdc++.h>
using namespace std;
#define fod(i,a,b) for(int i((int) (a)), _b(b); i <= _b; i++)
#define fok(i,a,b) for(int i((int) (a)), _b(b); i >= _b; i--)
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define ve vector
#define vi ve<int>
#define vll ve<ll>
#define el '\n'
#define mask(i) (1LL<<(i))
#define BIT(msk,i) (msk>>(i)&1LL)
template<class T> bool mini(T &a, T b){ return (a > (b) ? a = (b), 1 : 0); }
template<class T> bool maxi(T &a, T b){ return (a < (b) ? a = (b), 1 : 0); }
const int base = mask(20) + 5;
#define name "bitaro_party"

int n, m, q;

const int N = 1e5;
const int M = 2e5;
const int Q = 1e5;
const int SQRTN = 200;

ve <vi> g;

int dp[N + 5];

namespace sub1{
    bool check(){
        return (n <= 1000 and m <= 2000) or q == 1;
    }

    int host, num;

    void solve(){

        while(q--){
            cin >> host >> num;

          	fod(i,1,host) dp[i] = 0;

            fod(i,1,num){
                int x; cin >> x;
                dp[x] = -1e9;
            }

            fod(i,1,host){
                if(dp[i] >= 0) for(int j : g[i]){
                    if(j <= host) maxi(dp[j], dp[i] + 1);
                    else break;
                }
            }

            cout << max(dp[host], -1) << el;
        }
    }
}

namespace sub2{

    basic_string <pii> f[N + 5];

    int host;
    vi cant;

    bool del[N + 5];

    int solve_light(){
        for(pii x : f[host]) if(!del[x.se]) return x.fi;
        return -1;
    }

    int solve_heavy(){
        fod(i,1,host) dp[i] = 0;

        for(int x : cant) dp[x] = -1e9;

        fod(i,1,host){
            if(dp[i] >= 0) for(int j : g[i]){
                if(j <= host) maxi(dp[j], dp[i] + 1);
                else break;
            }
        }

        return max(dp[host], -1);
    }

    void solve(){
        fod(i,1,n){
            f[i].pb(mp(0, i));
            sort(f[i].begin(), f[i].end(), greater<pii>());
            while((int) f[i].size() > SQRTN) f[i].pop_back();

            for(int j : g[i]){
                for(pii x : f[i]) f[j].pb(mp(x.fi + 1, x.se));
            }
        }

        while(q--){
            cin >> host;
            int num; cin >> num;
            cant.clear();
            fod(i,1,num){
                int x; cin >> x;
                cant.pb(x);
            }

            for(int x : cant) del[x] = 1;

            if(num < SQRTN) cout << solve_light() << el;
            else cout << solve_heavy() << el;

            for(int x : cant) del[x] = 0;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    if(fopen(name".inp", "r")){
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }

    cin >> n >> m >> q;

    {
        int u, v;
        g.resize(n + 1);
        fod(i,1,m){
            cin >> u >> v;
            g[u].pb(v);
        }
    }

    fod(i,1,n) sort(g[i].begin(), g[i].end());

    if(sub1 :: check()) sub1 :: solve();
    else sub2 :: solve();

    return 0;
}

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

bitaro.cpp: In function 'int main()':
bitaro.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...