Submission #100693

#TimeUsernameProblemLanguageResultExecution timeMemory
100693JPN20Bitaro’s Party (JOI18_bitaro)C++17
14 / 100
2058 ms116340 KiB
#include <bits/stdc++.h> using namespace std; const int BACKET = 100; int N, M, Q, A[1 << 18], B[1 << 18], dp[1 << 18]; vector<int>X[1 << 18], Y[1 << 18]; pair<int, int> G[1 << 17][120], I[12000000]; int SZ[1 << 17]; bool used[1 << 18]; // --------------------------- 平方分割のそれぞれの解法 -------------------- int melee_solve(int pos, vector<int>vec) { for (int i = 0; i < (int)vec.size(); i++) used[vec[i]] = true; int maxn = -1; for (int i = 0; i < SZ[pos]; i++) { if (used[G[pos][i].second] == false) { maxn = max(maxn, G[pos][i].first); break; } } for (int i = 0; i < (int)vec.size(); i++) used[vec[i]] = false; return maxn; } int ranged_solve(int pos, vector<int>vec) { for (int i = 1; i <= N; i++) dp[i] = -1000000; for (int i = 0; i < (int)vec.size(); i++) used[vec[i]] = true; for (int i = 1; i <= N; i++) { if (used[i] == false) dp[i] = 0; for (int pos : Y[i]) { dp[i] = max(dp[i], dp[pos] + 1); } } for (int i = 0; i < (int)vec.size(); i++) used[vec[i]] = false; return max(-1, dp[pos]); } void init() { for (int i = 1; i <= N; i++) { int cntv = 0, cnts = 0; for (int pos : Y[i]) { for (int k = 0; k < SZ[pos]; k++) { I[cntv] = make_pair(G[pos][k].first + 1, G[pos][k].second); cntv++; } } I[cntv] = make_pair(0, i); cntv++; sort(I, I + cntv, greater<pair<int, int>>()); for (int j = 0; j < cntv; j++) { if (used[I[j].second] == false) { used[I[j].second] = true; G[i][cnts] = I[j]; cnts++; } if (cnts >= BACKET) break; } SZ[i] = cnts; for (int j = 0; j < cntv; j++) used[I[j].second] = false; } } int main(){ //FILE *in = freopen("in1.txt", "r", stdin); //FILE *out = freopen("out1.txt", "w", stdout); scanf("%d%d%d", &N, &M, &Q); for (int i = 0; i < M; i++) { scanf("%d%d", &A[i], &B[i]); X[A[i]].push_back(B[i]); Y[B[i]].push_back(A[i]); } init(); for (int i = 1; i <= Q; i++) { int P, S, C; vector<int>vec1; scanf("%d%d", &P, &S); for (int j = 0; j < S; j++) { scanf("%d", &C); vec1.push_back(C); } int ans = 0; if (S < BACKET) ans = melee_solve(P, vec1); else ans = ranged_solve(P, vec1); printf("%d\n", ans); } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &M, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &A[i], &B[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &P, &S);
   ~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:74:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &C); vec1.push_back(C);
    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...