제출 #534020

#제출 시각아이디문제언어결과실행 시간메모리
534020EvangBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1034 ms413636 KiB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

#ifdef _DEBUG
#define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el
#else
#define dout(x)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)

#define ins insert
#define ssize(x) (int((x).size()))
#define bs(args...) binary_search(args)
#define lb(args...) lower_bound(args)
#define ub(args...) upper_bound(args)
#define all(x) (x).begin(),(x).end()
#define mp(a, b) make_pair(a, b)
#define mt(args...) make_tuple(args)
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define die exit(0)

template<typename T>
using vc = vector<T>;
template<typename T>
using uset = unordered_set<T>;
template<typename A, typename B>
using umap = unordered_map<A, B>;
template<typename T, typename Comp>
using pq = std::priority_queue<T, vc<T>, Comp>;
template<typename T>
using maxpq = pq<T, less<T>>;
template<typename T>
using minpq = pq<T, greater<T>>;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using db = double;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vc<int>;
using vll = vc<ll>;
using vpi = vc<pi>;
using vpll = vc<pll>;
using str = string;

constexpr char el = '\n';
constexpr char sp = ' ';
constexpr int inf = 0x3f3f3f3f;
constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL;
// ---------------------------------------------------------------------


const int N = 1e5+5;
const int bsz = 350;
int n, m, q;
vi adj[N];  // reversed adj
vpi fur[N];

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout << fixed; clog << fixed; clog << unitbuf;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
#endif

    cin >> n >> m >> q;
    while(m--){
        int x, y;
        cin >> x >> y;
        adj[y].pb(x);
    }

    // calc fur[]
    for(int i = 1; i <= n; ++i){
        fur[i].eb(0, i);
        for(int j: adj[i]){
            vpi ans;

            vc<bool> vis(i+1);
            int p = 0, p2 = 0;
            while((p < ssize(fur[i]) || p2 < ssize(fur[j]))&&ssize(ans)<bsz){
                if(p2>=ssize(fur[j])||p<ssize(fur[i])
                                                   &&fur[i][p].ff>fur[j][p2].ff+1){
                    if(!vis[fur[i][p].ss]){
                        ans.pb(fur[i][p]);
                        vis[fur[i][p].ss] = 1;
                    }
                    ++p;
                }else{
                    if(!vis[fur[j][p2].ss]){
                        ans.eb(fur[j][p2].ff+1, fur[j][p2].ss);
                        vis[fur[j][p2].ss] = 1;
                    }
                    ++p2;
                }
            }
            swap(fur[i], ans);
        }
    }

    // print fur[]
#ifdef _DEBUG
    clog << "Line " << __LINE__ << ":\n";
    for(int i = 1; i <= n; ++i) {
        for (auto [d, v]: fur[i])
            clog << '(' << d << ", " << v << ") ";
        clog << el;
    }
    clog << el;
#endif

    while(q--){
        int t, y;
        cin >> t >> y;
        vi busy;
        for(int i = 0; i < y; ++i){
            int x;
            cin >> x;
            busy.pb(x);
        }
        sort(all(busy));

        if(y<bsz){
            for(auto[d, v]: fur[t])
                if(!bs(all(busy), v)){
                    cout << d << el;
                    goto next_query;
                }
            cout << -1 << el;
        }else{
            // naive dp
            vi dp(t+1);
            for(int i = 1; i <= t; ++i){
                if(bs(all(busy), i))
                    dp[i] = -inf;
                for(int j: adj[i])
                    dp[i] = max(dp[i], dp[j]+1);
            }

            if(dp[t]<0)
                cout << -1 << el;
            else
                cout << dp[t] << el;
        }

    next_query:;
    }
}

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

bitaro.cpp: In function 'int main()':
bitaro.cpp:97:52: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   96 |                 if(p2>=ssize(fur[j])||p<ssize(fur[i])
      |                                       ~~~~~~~~~~~~~~~
   97 |                                                    &&fur[i][p].ff>fur[j][p2].ff+1){
      |                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...