Submission #807702

#TimeUsernameProblemLanguageResultExecution timeMemory
807702AndiRSolar Storm (NOI20_solarstorm)C++14
100 / 100
598 ms169432 KiB
#include <iostream> #include <vector> using namespace std; typedef long long ll; const ll Nmax=1000000; ll n, s, k, d[Nmax], v[Nmax], r[Nmax]; ll st[Nmax+1], sol; ll spd[Nmax], spv[Nmax], mx; vector <ll >ad[Nmax+1]; ll dist(ll a, ll b){ if (a==b) return 0; if (a==0) return spd[b-1]; return spd[b-1]-spd[a-1]; } ll vp(ll a, ll b){ if (a==0) return spv[b]; return spv[b]-spv[a-1]; } void dfs(ll nod, ll lev){ st[lev]=nod; if (nod!=n){ ll l; if (lev<s) l=n-1; else l=st[lev-s]-1; //cout<<nod<<' '<<l<<'\n'; if (vp(nod, l)>mx){ mx=vp(nod, l); sol=nod; } } for (ll i=0; i<ad[nod].size(); i++) dfs(ad[nod][i], lev+1); } int main() { cin>>n>>s>>k; for (ll i=0; i<n-1 ;i++) cin>>d[i]; for (ll i=0; i<n; i++) cin>>v[i]; spd[0]=d[0]; for (ll i=1; i<n-1; i++) spd[i]=spd[i-1]+d[i]; spv[0]=v[0]; for (ll i=1; i<n; i++) spv[i]=spv[i-1]+v[i]; ///cautam cel mai din dreapta modul din intervalul k ll p1=0; for (ll i=0; i<n; i++) while (dist(p1, i)>k) r[p1++]=i-1; for (ll i=p1; i<n; i++) r[i]=n-1; ///cream arborele for (ll i=0; i<n; i++) ad[r[r[i]]+1].push_back(i); dfs(n, 0); cout<<s<<'\n'; for (ll i=0; i<s; i++){ //cout<<sol<<' '; if (sol==n) cout<<n<<' '; else{ cout<<r[sol]+1<<' '; sol=r[r[sol]]+1; } } return 0; }

Compilation message (stderr)

SolarStorm.cpp: In function 'void dfs(ll, ll)':
SolarStorm.cpp:38:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (ll i=0; i<ad[nod].size(); i++)
      |                  ~^~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...