Submission #714845

# Submission time Handle Problem Language Result Execution time Memory
714845 2023-03-25T10:44:38 Z BidoTeima Global Warming (NOI13_gw) C++17
19 / 40
939 ms 65536 KB
/*
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

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4388 KB Output is correct
2 Correct 42 ms 4424 KB Output is correct
3 Correct 26 ms 4312 KB Output is correct
4 Correct 26 ms 4252 KB Output is correct
5 Correct 26 ms 4376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 7004 KB Output is correct
2 Correct 47 ms 6904 KB Output is correct
3 Correct 63 ms 6972 KB Output is correct
4 Correct 63 ms 6948 KB Output is correct
5 Correct 62 ms 7016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 827 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 939 ms 53744 KB Memory limit exceeded
2 Halted 0 ms 0 KB -