제출 #1096183

#제출 시각아이디문제언어결과실행 시간메모리
1096183Zero_OPBitaro’s Party (JOI18_bitaro)C++14
14 / 100
1744 ms418320 KiB
#include "bits/stdc++.h" using namespace std; #define sz(v) (int)v.size() #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) const int MAX = 1e5 + 5; int SQRT = 350; int n, m, q, f[MAX]; vector<int> rev[MAX]; vector<pair<int, int>> dp[MAX]; //[dist, u] bool bad[MAX]; template<typename T> void add(vector<T>& S, T nw){ if(S.empty() || S.back() != nw) S.push_back(nw); } void insert(vector<pair<int, int>> &A, vector<pair<int, int>>& B){ //B + 1 A.insert(A.end(), all(B)); sort(all(A), greater<pair<int, int>>()); compact(A); if(A.size() > SQRT + 1) A.resize(SQRT + 1); } bool filled[MAX]; bool checking(const vector<pair<int, int>>& S){ for(auto [d, u] : S){ if(filled[u]){ assert(false); } filled[u] = true; } for(auto [d, u] : S){ filled[u] = false; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("task.inp", "r", stdin); // freopen("task.out", "w", stdout); cin >> n >> m >> q; for(int i = 0; i < m; ++i){ int u, v; cin >> u >> v; rev[v].push_back(u); } SQRT = sqrt(n); for(int i = 1; i <= n; ++i){ dp[i].push_back({0, i}); for(int j : rev[i]){ insert(dp[i], dp[j]); } // checking(dp[i]); } // for(int i = 1; i <= n; ++i){ // cout << i << " :\n"; // for(auto j : S[i]) cout << j.first << ' ' << j.second << '\n'; cout << '\n'; // } while(q--){ int t, y; cin >> t >> y; vector<int> nodes(y); for(int i = 0; i < y; ++i) cin >> nodes[i]; for(int u : nodes) bad[u] = true; if(y > SQRT){ // cout << "heavy\n"; fill(f + 1, f + 1 + n, -1e9); f[t] = 0; for(int i = t; i > 0; --i){ for(int j : rev[i]){ f[j] = max(f[j], f[i] + 1); } } int ans = -1; for(int i = t; i > 0; --i){ if(!bad[i]) ans = max(ans, f[i]); } cout << ans << '\n'; } else{ // cout << "light\n"; int ans = -1; for(auto u : dp[t]){ if(!bad[u.second]){ ans = u.first; break; } } if(ans == -1){ cout << ans << '\n'; } else{ cout << ans << '\n'; } } for(int u : nodes) bad[u] = false; } return 0; } /* test 1 : 5 6 3 1 2 2 4 3 4 1 3 3 5 4 5 4 1 1 5 2 2 3 2 3 1 4 5 test 2 : 12 17 10 1 2 2 3 3 4 1 5 2 6 3 7 4 8 5 6 6 7 7 8 5 9 6 10 7 11 8 12 9 10 10 11 11 12 6 3 1 7 12 3 7 1 2 3 4 5 6 7 11 3 1 3 5 9 2 1 9 8 4 1 2 3 4 1 1 1 12 0 10 3 1 6 10 11 8 2 3 5 6 7 9 10 11 8 7 2 3 4 5 6 7 8 test 3 : 12 17 1 1 2 2 3 3 4 1 5 2 6 3 7 4 8 5 6 6 7 7 8 5 9 6 10 7 11 8 12 9 10 10 11 11 12 12 0 */

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

bitaro.cpp: In function 'void insert(std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&)':
bitaro.cpp:28:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |     if(A.size() > SQRT + 1) A.resize(SQRT + 1);
      |        ~~~~~~~~~^~~~~~~~~~
bitaro.cpp: In function 'bool checking(const std::vector<std::pair<int, int> >&)':
bitaro.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |     for(auto [d, u] : S){
      |              ^
bitaro.cpp:42:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |     for(auto [d, u] : S){
      |              ^
bitaro.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
   45 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...