제출 #284987

#제출 시각아이디문제언어결과실행 시간메모리
284987PlurmBitaro’s Party (JOI18_bitaro)C++11
0 / 100
29 ms31352 KiB
#include <bits/stdc++.h> using namespace std; const int THRESH = 300; vector<int> ord; vector<int> g[100005]; vector<int> rg[100005]; bool found[100005]; void dfs(int u){ if(found[u]) return; found[u] = true; for(int v : g[u]){ dfs(v); } ord.push_back(u); } vector<pair<int,int> > dp[1000005]; // | dp[i] | <= THRESH. void merge(vector<pair<int,int> >& dest, vector<pair<int,int> > src){ for(auto& v : src) v.first++; vector<pair<int,int> > newVec; int ptr1 = 0; int ptr2 = 0; while(ptr1 < dest.size() && ptr2 < src.size() && ptr1 + ptr2 < THRESH){ if(dest[ptr1].first > src[ptr2].first){ newVec.emplace_back(dest[ptr1]); ptr1++; }else{ newVec.emplace_back(src[ptr2]); ptr2++; } } while(ptr1 + ptr2 < THRESH && ptr1 < dest.size()){ newVec.emplace_back(dest[ptr1]); ptr1++; } while(ptr1 + ptr2 < THRESH && ptr2 < src.size()){ newVec.emplace_back(src[ptr2]); ptr2++; } swap(dest, newVec); } bool isBusy[100005]; int subdp[100005]; int recalculateAnswer(int t){ memset(subdp, 0, sizeof(subdp)); for(int u : ord){ subdp[u] = isBusy[u] ? -1000000 : 0; for(int v : rg[u]){ subdp[u] = max(subdp[u], subdp[v]+1); } subdp[u] = max(subdp[u], 0); } return subdp[t]; } int main(){ int n, m, q; scanf("%d%d%d",&n,&m,&q); for(int i = 0; i < m; i++){ int s,e; scanf("%d%d",&s,&e); g[s].push_back(e); rg[e].push_back(s); } for(int i = 1; i <= n; i++) dfs(i); reverse(ord.begin(), ord.end()); for(int u : ord){ for(int v : rg[u]){ merge(dp[u], dp[v]); } merge(dp[u], {make_pair(-1, u)}); } while(q--){ int t, y; scanf("%d%d",&t,&y); vector<int> busy; for(int i = 0; i < y; i++){ int c; scanf("%d",&c); busy.push_back(c); isBusy[c] = true; } int ans = -1; if(y < THRESH){ for(auto p : dp[t]){ if(isBusy[p.second]) continue; ans = p.first; break; } }else{ ans = recalculateAnswer(t); } for(int x : busy) isBusy[x] = false; printf("%d\n",ans); } return 0; }

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

bitaro.cpp: In function 'void merge(std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >)':
bitaro.cpp:22:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  while(ptr1 < dest.size() && ptr2 < src.size() && ptr1 + ptr2 < THRESH){
      |        ~~~~~^~~~~~~~~~~~~
bitaro.cpp:22:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  while(ptr1 < dest.size() && ptr2 < src.size() && ptr1 + ptr2 < THRESH){
      |                              ~~~~~^~~~~~~~~~~~
bitaro.cpp:31:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  while(ptr1 + ptr2 < THRESH && ptr1 < dest.size()){
      |                                ~~~~~^~~~~~~~~~~~~
bitaro.cpp:35:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  while(ptr1 + ptr2 < THRESH && ptr2 < src.size()){
      |                                ~~~~~^~~~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |  scanf("%d%d%d",&n,&m,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
bitaro.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |   scanf("%d%d",&s,&e);
      |   ~~~~~^~~~~~~~~~~~~~
bitaro.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |   scanf("%d%d",&t,&y);
      |   ~~~~~^~~~~~~~~~~~~~
bitaro.cpp:77:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |    scanf("%d",&c);
      |    ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...