Submission #1186382

#TimeUsernameProblemLanguageResultExecution timeMemory
1186382swishy123Bitaro’s Party (JOI18_bitaro)C++20
100 / 100
1064 ms245480 KiB
#include <iostream> #include <algorithm> #include <vector> #include <random> #include <chrono> #include <set> #include <map> #include <stack> #include <functional> #include <iomanip> #include <queue> #include <cassert> #include <complex> #include <cstring> #include <memory> #include <bitset> #include <sstream> #include <cmath> #include <numeric> #include <numbers> #include <fstream> using namespace std; #ifndef template #ifndef define #define ll long long #define ld long double #define pl pair<ll, ll> #define pi pair<int, int> #define nl cout << '\n'; #define x first #define y second #define cbit(x) __builtin_popcountll(x) #define uid(a, b) uniform_int_distribution<ll>(a, b)(rng) #define siz(x) (int)x.size() #endif #ifndef print void print(size_t x) {cout << x << ' ';} void print(int x) {cout << x << ' ';} void print(long long x) {cout << x << ' ';} void print(float x) {cout << x << ' ';} void print(long double x) {cout << x << ' ';} void print(char x) {cout << x << ' ';} void print(const char* x) {cout << x << ' ';} void print(bool x) {cout << x << ' ';} void print(string &x) {cout << x << ' ';} template<typename T, typename V> void print(pair<T, V> &p) {print(p.x); print(p.y);} template<typename T> void print(vector<T> v) {for (int i = 0; i < v.size(); i++) print(v[i]);} template<typename T> void print(vector<vector<T>> v) { for (int i = 0; i < v.size(); i++){ for (int j = 0; j < v[i].size(); j++) print(v[i][j]); nl; } } template <typename T, typename... V> void print(T t, V&&... v) {print(t); print(v...);} #endif #ifndef read void read(int &x) {cin >> x;} void read(long long &x) {cin >> x;} void read(unsigned &x) {cin >> x;} void read(unsigned long long &x) {cin >> x;} void read(float &x) {cin >> x;} void read(long double &x) {cin >> x;} void read(char &x) {cin >> x;} void read(string &x) {cin >> x;} void read(bool &x) {cin >> x;} template<typename T> void read(vector<T> &v) { for (int i = 0; i < v.size(); i++) read(v[i]); } template <typename T, typename... V> void read(T &t, V&... v) {read(t); read(v...);} #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> bool maxi(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> bool mini(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class... Args> auto vec(size_t n, Args&&... args) { if constexpr(sizeof...(args) == 1) return vector(n, args...); else return vector(n, vec(args...)); } #endif using namespace std; const ll inf = 1e18; const ll def = 1e5+1; const ll mod = 1e9+9; using namespace std; int block = 300; vector<vector<pi>> best(def); void solve(){ int n, m, q; read(n, m, q); vector<vector<int>> edg(n); for (int i = 0; i < m; i++){ int u, v; read(u, v); u--; v--; edg[v].push_back(u); } for (int i = 0; i < n; i++) best[i].push_back({0, i}); auto marked = vec(n, 0); for (int u = 0; u < n; u++){ for (int v : edg[u]){ vector<pi> newbest; int j = 0; for (int i = 0; i <= best[v].size(); i++){ while (j < best[u].size() && (i == best[v].size() || best[u][j].x > best[v][i].x + 1)){ if (newbest.size() == block) break; if (!marked[best[u][j].y]) newbest.push_back(best[u][j]); marked[best[u][j++].y] = 1; } if (newbest.size() == block || i == best[v].size()) break; if (!marked[best[v][i].y]) newbest.push_back({best[v][i].x + 1, best[v][i].y}); marked[best[v][i].y] = 1; } for (auto it : newbest) marked[it.y] = 0; best[u] = newbest; } } while (q--){ int u, s; read(u, s); u--; vector<int> blocked(s); read(blocked); for (int x : blocked) marked[x - 1] = 1; int res = -1; if (s < block){ for (int i = 0; i < best[u].size(); i++){ if (marked[best[u][i].y]) continue; res = best[u][i].x; break; } } else{ auto dp = vec(n, -1); for (int i = 0; i < n; i++){ if (!marked[i]) maxi(dp[i], 0); for (int v : edg[i]){ if (dp[v] == -1) continue; maxi(dp[i], dp[v] + 1); } } res = dp[u]; } for (int x : blocked) marked[x - 1] = 0; print(res); nl; } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (ifstream("input.txt").good()){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int t = 1; while (t--){ solve(); nl; } return 0; }

Compilation message (stderr)

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