Submission #1076668

#TimeUsernameProblemLanguageResultExecution timeMemory
1076668allin27xRadio Towers (IOI22_towers)C++17
0 / 100
10 ms2260 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<int> h; vector<int> lc,rc,a; void init(signed N, std::vector<signed> H){ h.resize(N); for (int i = 0; i < N; i++) h[i] = H[i]; } int dfs(int i, int d){ if (i==-1) return 0; if (lc[i]==-1 && rc[i]==-1) return -a[i]; int lans = dfs(lc[i],d); int rans = dfs(rc[i],d); if (lans < 0 && a[i] - d >= a[lc[i]]) lans = 1; if (rans < 0 && a[i] - d >= a[rc[i]]) rans = 1; if (!lans) return rans; if (!rans) return lans; if (lans < 0 && rans < 0) return max(lans,rans); if (lans < 0) return rans; if (rans < 0) return lans; return lans + rans; } signed max_towers(signed l, signed r, signed d){ int sz = r-l+1; a.assign(sz,0); for (int i=l; i<=r; i++) a[i-l] = h[i]; a.push_back(2e9); stack<int> st; st.push(sz); lc.assign(sz+1,-1); rc.assign(sz+1,-1); for (int i=0; i<sz; i++){ int last = -1; while (a[i] > a[st.top()]) { last=st.top(); st.pop(); } lc[i] = last; rc[st.top()]=i; st.push(i); } for (int i=0; i<=sz; i++) cout<<i<<' '<<lc[i]<<' '<<rc[i]<<'\n'; cout<<'\n'; return dfs(sz,d); }

Compilation message (stderr)

towers.cpp: In function 'long long int dfs(long long int, long long int)':
towers.cpp:19:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   19 |  if (!lans) return rans; if (!rans) return lans;
      |  ^~
towers.cpp:19:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   19 |  if (!lans) return rans; if (!rans) return lans;
      |                          ^~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:44:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |  for (int i=0; i<=sz; i++) cout<<i<<' '<<lc[i]<<' '<<rc[i]<<'\n'; cout<<'\n';
      |  ^~~
towers.cpp:44:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |  for (int i=0; i<=sz; i++) cout<<i<<' '<<lc[i]<<' '<<rc[i]<<'\n'; cout<<'\n';
      |                                                                   ^~~~
#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...