제출 #896295

#제출 시각아이디문제언어결과실행 시간메모리
896295Muhammad_Aneeq던전 (IOI21_dungeons)C++17
11 / 100
138 ms43048 KiB
#include <vector> #include <set> #include <map> #include <algorithm> using namespace std; int const N=5e4+10; long long wi[N],lo[N],po[N],st[N]; int nn; set<int>sr; vector<int>nei[N]={}; long long head[N]={},cost[N]={},cost1[N]={}; int vis[N]={}; vector<vector<pair<int,long long>>>heads; void dfs(int n,long long val=0) { for (auto i:nei[n]) { cost1[i]+=st[i]; cost1[i]+=cost1[n]; dfs(i); } } void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { nn=n; for (int i=0;i<n;i++) { wi[i]=w[i]; lo[i]=l[i]; st[i]=s[i]; po[i]=p[i]; nei[w[i]].push_back(i); head[i]=-1; sr.insert(s[i]); } if (sr.size()==1) { dfs(n); int o=0; for (int i=0;i<n;i++) { if (head[i]==-1) { int j=i; vector<int>temp; while (!vis[j]) { temp.push_back(j); vis[j]=1; j=lo[j]; } if (head[j]==-1) { int k; for (k=0;k<temp.size();k++) if (temp[k]==j) break; long long z=0; for (int l=k-1;l>=0;l--) { z+=po[temp[l]]; cost[temp[l]]=z; } z=0; for (int l=temp.size();l>k;l--) { z+=po[temp[l]]; cost[temp[l]]=z; } cost[temp[k]]=0; for (auto t:temp) head[t]=heads.size(); reverse(begin(temp),end(temp)); while (temp.back()!=j) { temp.pop_back(); } vector<pair<int,long long>>pre(temp.size()+1); reverse(begin(temp),end(temp)); pre[0]={temp[0],0}; for (int l=1;l<temp.size();l++) pre[l]={temp[l],pre[l-1].second+po[temp[l-1]]}; pre[temp.size()]={temp[0],pre[temp.size()-1].second+po[temp.back()]}; heads.push_back(pre); } else { for (auto k:temp) head[k]=head[j]; long long z=cost[j]; reverse(begin(temp),end(temp)); for (auto k:temp) { z+=po[k]; cost[k]=z; } } } } } } bool yu=0; long long simulate(int i, int z) { if (sr.size()==1) { long long f=*begin(sr); long long ans=z; if (ans+cost[i]>f) { while (ans<f) { ans+=po[i]; i=lo[i]; } ans+=cost1[i]; } else { ans+=cost[i]; long long y=heads[head[i]].back().second; long long r=(f-ans-1)/y; r=max(r,0LL); ans+=y*r; int st=-1,en=heads[head[i]].size(); r=f-ans; while (st+1<en) { int mid=(st+en)/2; if (heads[head[i]][mid].second>=r) en=mid; else st=mid; } ans+=heads[head[i]][en].second; ans+=cost1[heads[head[i]][en].first]; yu=1; } return ans; } long long ans=z; while (i!=nn) { if (ans>=st[i]) { ans+=st[i]; i=wi[i]; } else { ans+=po[i]; i=lo[i]; } } return ans; }

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

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |      for (k=0;k<temp.size();k++)
      |               ~^~~~~~~~~~~~
dungeons.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |      for (int l=1;l<temp.size();l++)
      |                   ~^~~~~~~~~~~~
dungeons.cpp:39:7: warning: unused variable 'o' [-Wunused-variable]
   39 |   int o=0;
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...