제출 #985734

#제출 시각아이디문제언어결과실행 시간메모리
985734SmuggingSpunBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1554 ms423824 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; const int INF = 1e9; template<class T>void maximize(T& a, T b){ if(a < b){ a = b; } } int n, m, q; namespace sub12{ const int lim = 1e5 + 5; vector<int>e[lim]; int dp[lim]; void solve(){ for(int _ = 0; _ < m; _++){ int u, v; cin >> u >> v; e[v].emplace_back(u); } int t, y; cin >> t >> y; bitset<lim>busy; busy.reset(); for(int _ = 0; _ < y; _++){ int x; cin >> x; busy.set(x); } for(int i = 1; i <= n; i++){ dp[i] = (busy.test(i) ? -INF : 0); for(int& v : e[i]){ maximize(dp[i], dp[v] + 1); } } cout << max(dp[t], -1); } } namespace sub3{ const int lim = 2e5 + 5; const int SIZE = 320; vector<int>e[lim]; vector<pair<int, int>>candidate[lim]; int dp[lim], d[lim], vis[lim]; void solve(){ for(int _ = 0; _ < m; _++){ int u, v; cin >> u >> v; e[v].emplace_back(u); } memset(d, 0, sizeof(d)); memset(vis, 0, sizeof(vis)); for(int i = 1; i <= n; i++){ vector<int>current(1, i); for(int& j : e[i]){ for(auto& [w, k] : candidate[j]){ if(vis[k] == i){ maximize(d[k], w + 1); } else{ current.emplace_back(k); vis[k] = i; d[k] = w + 1; } } } for(int& x : current){ candidate[i].emplace_back(d[x], x); } sort(candidate[i].begin(), candidate[i].end(), greater<pair<int, int>>()); if(candidate[i].size() > SIZE){ candidate[i].erase(candidate[i].begin() + SIZE, candidate[i].end()); } } memset(vis, -1, sizeof(vis)); for(int _i = 0; _i < q; _i++){ int t, y; cin >> t >> y; for(int i = 0; i < y; i++){ int x; cin >> x; vis[x] = _i; } if(y < SIZE){ int ans = -1; for(auto& [w, u] : candidate[t]){ if(vis[u] != _i){ ans = w; break; } } cout << ans << "\n"; continue; } memset(dp, -1, sizeof(dp)); for(int i = 1; i <= n; i++){ if(vis[i] != _i){ dp[i] = 0; } for(int& v : e[i]){ if(dp[v] != -1){ maximize(dp[i], dp[v] + 1); } } } cout << dp[t] << "\n"; } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> m >> q; if(q == 1){ sub12::solve(); } else{ sub3::solve(); } }

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

bitaro.cpp: In function 'void sub3::solve()':
bitaro.cpp:56:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |     for(auto& [w, k] : candidate[j]){
      |               ^
bitaro.cpp:86:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   86 |     for(auto& [w, u] : candidate[t]){
      |               ^
bitaro.cpp: In function 'int main()':
bitaro.cpp:113:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...