제출 #1190145

#제출 시각아이디문제언어결과실행 시간메모리
1190145jioungBitaro’s Party (JOI18_bitaro)C++20
100 / 100
1036 ms416544 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define NAME ""
#define eb emplace_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define REP(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define FORD(i, a, b, x) for (int i = (a), _b = (b); i <= _b; i += x)

const int MAX = 100005, BLOCK = sqrt(MAX) + 1, LOG = __lg(MAX) + 1, mod = 1e9 + 7;
const int INF = 1e18;
typedef long long ll;

namespace Solution
{
    int n, m, q;
    vector<int> adj[MAX], radj[MAX];
    vector<pii> vi[MAX];
    bool vis[MAX];
    int dist[MAX];

    void solve()
    {
        cin >> n >> m >> q;
        FOR(i, 1, m)
        {
            int u, v;
            cin >> u >> v;
            adj[u].eb(v);
            radj[v].eb(u);
        }
        FOR(i, 1, n)
        {
            vi[i].clear();
            vi[i].eb(0, i);
        }
        FOR(u, 1, n)
        {
            for (auto v : radj[u])
            {
                vector<pii> tmp;
                vi[v].eb(0, v);
                int ni = vi[u].size();
                int nj = vi[v].size();
                int i = 0, j = 0;
                while (tmp.size() < BLOCK && (i < ni || j < nj))
                {
                    if (i == ni || (j < nj && vi[v][j].fi + 1 >= vi[u][i].fi))
                    {
                        tmp.eb(vi[v][j].fi + 1, vi[v][j].se);
                        vis[vi[v][j].se] = true;
                        j++;
                    }
                    else
                    {
                        tmp.eb(vi[u][i]);
                        vis[vi[u][i].se] = true;
                        i++;
                    }
                    while (i < ni && vis[vi[u][i].se])
                        i++;
                    while (j < nj && vis[vi[v][j].se])
                        j++;
                }
                vi[v].pop_back();
                for (auto &p : tmp)
                    vis[p.se] = false;
                swap(vi[u], tmp);
            }
        }

        while (q--)
        {
            int t, y;
            cin >> t >> y;
            vector<int> blocked;
            blocked.reserve(y);
            FOR(i, 1, y)
            {
                int x;
                cin >> x;
                vis[x] = true;
                blocked.eb(x);
            }
            if (y < BLOCK)
            {
                int ans = -1;
                for (auto &p : vi[t])
                    if (p.fi > ans && !vis[p.se])
                        ans = p.fi;
                if (!vis[t])
                    ans = max(ans, 0);
                cout << ans << '\n';
            }
            else
            {
                int ans = -1;
                FOR(i, 1, n)
                {
                    dist[i] = -1;
                }
                dist[t] = 0;
                if (!vis[t])
                    ans = 0;
                REP(i, t - 1, 1)
                {
                    for (auto v : adj[i])
                    {
                        if (dist[v] != -1)
                        {
                            dist[i] = max(dist[i], dist[v] + 1);
                        }
                    }
                    if (dist[i] != -1 && !vis[i])
                        ans = max(ans, dist[i]);
                }
                cout << ans << '\n';
            }
            for (int x : blocked)
                vis[x] = false;
        }
    }
}
signed main()
{
    if (fopen(NAME ".inp", "r"))
    {
        freopen(NAME ".inp", "r", stdin);
        freopen(NAME ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Solution::solve();
    return 0;
}

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

bitaro.cpp:14:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   14 | const int INF = 1e18;
      |                 ^~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         freopen(NAME ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:132:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |         freopen(NAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...