제출 #1007805

#제출 시각아이디문제언어결과실행 시간메모리
1007805n3rm1nBitaro’s Party (JOI18_bitaro)C++17
0 / 100
169 ms298576 KiB
#include<bits/stdc++.h> #define endl '\n' #define ll long long using namespace std; const int MAXN = 2e5 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, m, q; vector < int > g[MAXN], grev[MAXN]; int tt, yy; void read() { cin >> n >> m >> q; int from, to; for (int i = 1; i <= m; ++ i) { cin >> from >> to; g[from].push_back(to); grev[to].push_back(from); } } int marked[MAXN], dp[MAXN]; deque < pair < int, int > > opt[MAXN]; int c[MAXN], f[MAXN]; deque < pair < int, int > > comb(deque < pair < int, int > > f, deque < pair < int, int > > s) { deque < pair < int, int > > q; while(f.size() && s.size() && q.size() < sqrt(n)) { pair <int, int > ft = f.front(); pair < int, int > st = s.front(); st.first ++; if(ft.first > st.first) { f.pop_front(); if(!q.size() || (q.size() && ft != q.front()))q.push_back(ft); } else { s.pop_front(); if(!q.size() || (q.size() && st != q.front()))q.push_back(st); } } while(f.size() && q.size() < sqrt(n)) { pair <int, int > ft = f.front(); f.pop_front(); if(!q.size() || (q.size() && ft != q.front()))q.push_back(ft); } while(s.size() && q.size() < sqrt(n)) { pair <int, int > st = s.front(); st.first ++; s.pop_front(); if(!q.size() || (q.size() && st != q.front()))q.push_back(st); } return q; } void precompute_small() { opt[1].push_back(make_pair(0, 1)); for (int i = 2; i <= n; ++ i) { int apar; deque < pair < int, int > > qq; qq.push_back(make_pair(0, i)); opt[i] = comb(qq, opt[grev[i][0]]); for (int j = 1; j < grev[i].size(); ++ j) { apar = grev[i][j]; opt[i] = comb(opt[i], opt[apar]); } } /*for (int i =1;i <= n; ++ i) { cout << "for i " << i << endl; for (int j = 0; j < opt[i].size(); ++ j) cout << " (" <<opt[i][j].first << "," << opt[i][j].second <<") "; cout <<endl; }*/ } void solve_small() { //cout << "is small" << endl; int maxx = -1; for (int i = 0; i < opt[tt].size(); ++ i) { if(!marked[opt[tt][i].second]) maxx = max(maxx, opt[tt][i].first); } cout << maxx << endl; } void solve_big() { //cout << "is big" << endl; for (int i = 1; i <= n; ++ i) dp[i] = -1; int maxx = -1, cnt = 0; for (int i = tt; i >= 1; -- i) { if(i == tt) { dp[i] = 0; if(!marked[i]) maxx = 0; continue; } for (int j = 0; j < g[i].size(); ++ j) { int nb = g[i][j]; if(dp[nb] != -1)dp[i] = max(dp[i], dp[nb] + 1); } /// cout << dp[i] << endl; if(!marked[i])maxx = max(maxx, dp[i]); } cout << maxx << endl; } int main() { speed(); read(); precompute_small(); while(q --) { cin >> tt >> yy; for (int i = 1; i <= yy; ++ i) { cin >> c[i]; marked[c[i]] = 1; } if(yy >= sqrt(n)) { solve_big(); } else solve_small(); for (int i = 1; i <= yy; ++ i) { marked[c[i]] = 0; } } return 0; } /*** 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 6 3 1 7 12 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 /*/

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

bitaro.cpp: In function 'void precompute_small()':
bitaro.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int j = 1; j < grev[i].size(); ++ j)
      |                         ~~^~~~~~~~~~~~~~~~
bitaro.cpp: In function 'void solve_small()':
bitaro.cpp:95:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for (int i = 0; i < opt[tt].size(); ++ i)
      |                     ~~^~~~~~~~~~~~~~~~
bitaro.cpp: In function 'void solve_big()':
bitaro.cpp:118:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |         for (int j = 0; j < g[i].size(); ++ j)
      |                         ~~^~~~~~~~~~~~~
bitaro.cpp:108:20: warning: unused variable 'cnt' [-Wunused-variable]
  108 |     int maxx = -1, cnt = 0;
      |                    ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...