Submission #714845

#TimeUsernameProblemLanguageResultExecution timeMemory
714845BidoTeimaGlobal Warming (NOI13_gw)C++17
19 / 40
939 ms65536 KiB
/* ID: BidoTeima LANG: C++11 TASK: */ #include <bits/stdc++.h> using namespace std; using ll = long long; void moo(string filename); void ACPLS(string str = "") { if(str=="NOF")return; if(str.size() && str != "IIOT") moo(str); else if(str != "IIOT"){ #ifndef ONLINE_JUDGE freopen("output.txt", "w", stdout); freopen("input.txt", "r", stdin); #endif } ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void moo(string fileName){ freopen((fileName+".in").c_str(),"r",stdin); freopen((fileName+".out").c_str(),"w",stdout); } #define tcccc \ int tttttt/*,subtask*/; \ cin >> tttttt/* >> subtask*/; \ while (tttttt--)/*end */ int main() { //ACPLS(""); int n; cin>>n; n += 2; int a[n], cur = 0; a[0] = 0; for(int i = 1; i < n - 1; i++){ cin>>a[i]; } a[n - 1] = 0; vector<int>c; for(int i = 0; i < n; i++){ if(i && a[i] == a[i - 1])continue; c.push_back(a[i]); } n = (int)c.size(); vector<int>mp[n]; int sorted[n]; copy(c.begin(),c.end(),sorted); sort(sorted,sorted+n); // mp[i] has all occurences of sorted[i] for(int i = 0; i < n; i++){ int idx = lower_bound(sorted,sorted+n,c[i]) - sorted; mp[idx].push_back(i); c[i] = idx; } int ans = 0; bool nextIsIsland = 0; for(int i = 0; i < n; i++){ if(c[i] == 0)nextIsIsland = 1; else{ cur += nextIsIsland; nextIsIsland = 0; } } ans=max(ans,cur); for(int j = 1; j < n; j++){ vector<int>&v = mp[j]; for(int i = 0; i < (int)v.size(); i++){ int val = (c[v[i] - 1] < j) + (c[v[i] + 1] < j); if(val == 0){ cur++; } else if(val == 2){ cur--; } } ans = max(ans, cur); } cout<<ans<<'\n'; }

Compilation message (stderr)

gw.cpp: In function 'void ACPLS(std::string)':
gw.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
gw.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
gw.cpp: In function 'void moo(std::string)':
gw.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((fileName+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gw.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((fileName+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...