제출 #418636

#제출 시각아이디문제언어결과실행 시간메모리
418636cpp219Bitaro’s Party (JOI18_bitaro)C++14
14 / 100
1306 ms293828 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 = 1e5 + 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],dd[N]; ll DFS(ll u){ if (val[u] != -1) return val[u]; if (u == target) return 0; ll ans = -inf; for (auto i : g[u]) ans = max(ans,1 + DFS(i)); return val[u] = ans; } deque<LL> dq[N]; /// fs = val sc = id int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "test" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n>>m>>Q; S = sqrt(n); while(m--){ cin>>x>>y; g[x].push_back(y); rg[y].push_back(x); } for (ll i = 1;i <= n;i++){ bool flag = 0; //cout<<rg[i].size(); //return 0; for (ll j = 0;j < rg[i].size();j++) dd[j] = 0; //return 0; while(dq[i].size() < S){ LL mx = {-1,i}; if (flag) mx = {-inf,0}; for (auto j : rg[i]){ ll cur = dd[j]; if (cur < dq[j].size()) mx = max(mx,dq[j][cur]); } if (mx.sc == i) flag = 1; dq[i].push_back({mx.fs + 1,mx.sc}); for (auto j : rg[i]){ ll cur = dd[j]; if (cur >= dq[j].size()) continue; if (mx == dq[j][cur]) dd[j]++; } } //return 0; } //return 0; /* 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 'int main()':
bitaro.cpp:42:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (ll j = 0;j < rg[i].size();j++) dd[j] = 0; //return 0;
      |                       ~~^~~~~~~~~~~~~~
bitaro.cpp:43:28: warning: comparison of integer expressions of different signedness: 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |         while(dq[i].size() < S){
      |               ~~~~~~~~~~~~~^~~
bitaro.cpp:48:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 if (cur < dq[j].size()) mx = max(mx,dq[j][cur]);
      |                     ~~~~^~~~~~~~~~~~~~
bitaro.cpp:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |                 if (cur >= dq[j].size()) continue;
      |                     ~~~~^~~~~~~~~~~~~~~
bitaro.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...