제출 #418596

#제출 시각아이디문제언어결과실행 시간메모리
418596cpp219Bitaro’s Party (JOI18_bitaro)C++14
0 / 100
204 ms292548 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 9; const ll inf = 1e9 + 7; typedef pair<ll,ll> LL; vector<ll> g[N],rg[N],v; ll n,m,Q,x,y,sz,target,S,val[N]; ll ban[N]; ll DFS(ll u){ if (val[u] != -1) return val[u]; if (u == target) return 0; ll ans = -2*inf; for (auto i : g[u]) ans = max(ans,1 + DFS(i)); return val[u] = ans; } deque<LL> dq[N]; /// fs = val sc = id void Merge(deque<LL> &a,deque<LL> b){ deque<LL> res; //cout<<a.size(); exit(0); while(res.size() < S){ LL c1 = {-inf,0},c2 = {-inf,0}; if (!a.empty()) c1 = a.front(); if (!b.empty()) c2 = b.front(); c2.fs++; res.push_back(max(c1,c2)); if (max(c1,c2) == c1){ a.pop_front(); if (c1 == c2) b.pop_front(); } else{ b.pop_front(); if (c1 == c2) a.pop_front(); } } a.clear(); for (auto i : res) a.push_back(i); res.clear(); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n>>m>>Q; S = 100; while(m--){ cin>>x>>y; g[x].push_back(y); rg[y].push_back(x); } for (ll i = 1;i <= n;i++){ deque<LL> now; now.push_back({-1,i}); Merge(dq[i],now); for (auto j : rg[i]) Merge(dq[i],dq[j]); } /* for (ll i = 1;i <= n;i++){ cout<<i<<":\n"; for (auto j : dq[i]) cout<<j.fs<<" "<<j.sc<<"\n"; cout<<"\n"; } return 0;*/ while(Q--){ cin>>target>>sz; v.clear(); for (ll i = 1;i <= sz;i++) cin>>x,v.push_back(x),ban[x] = 1; if (sz >= S){ memset(val,-1,sizeof(val)); ll ans = -1; for (ll i = 1;i <= n;i++){ if (ban[i]) continue; ans = max(ans,DFS(i)); //cout<<i<<" "<<DFS(i)<<"\n"; } cout<<ans<<"\n"; } else{ LL ans = {-1,0}; for (auto i : dq[target]) if (!ban[i.sc]) ans = max(ans,i); cout<<ans.fs<<"\n"; } for (auto i : v) ban[i] = 0; } }

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

bitaro.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
bitaro.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
bitaro.cpp: In function 'void Merge(std::deque<std::pair<int, int> >&, std::deque<std::pair<int, int> >)':
bitaro.cpp:29:22: warning: comparison of integer expressions of different signedness: 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     while(res.size() < S){
      |           ~~~~~~~~~~~^~~
bitaro.cpp:44:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |     for (auto i : res) a.push_back(i); res.clear();
      |     ^~~
bitaro.cpp:44:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |     for (auto i : res) a.push_back(i); res.clear();
      |                                        ^~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...