Submission #395820

# Submission time Handle Problem Language Result Execution time Memory
395820 2021-04-29T02:42:56 Z Qw3rTy Global Warming (CEOI18_glo) C++11
0 / 100
19 ms 1472 KB
#include <bits/stdc++.h>
#define INF 1e9+5
#define pb push_back
using namespace std;

const int maxN = 1e5+5;

int a[maxN];
int f[maxN]; //length of LIS that ends on a[i]
int g[maxN]; //Length of longest decreasing subsequence that ends at a[i]
int N,d;

bool cmp(const int &a, const int &b){return a > b;}

void testIO(){
    freopen("../test.in","r",stdin);
    return;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //testIO();
    cin >> N >> d;
    for(int i = 1; i <= N; ++i)cin >> a[i];
    //Calculate f
    vector<int> dp;
    for(int i = 1; i <= N; ++i){
        int pos = lower_bound(dp.begin(),dp.end(),a[i]) - dp.begin();
        if(pos == dp.size())
            dp.pb(a[i]);
        else dp[pos] = a[i];
        f[i] = dp.size();
    }
    //Calculate g
    dp.clear();
    for(int i = N; i >= 1; --i){
        int pos = lower_bound(dp.begin(),dp.end(),a[i],cmp) - dp.begin();
        if(pos == dp.size())
            dp.pb(a[i]);
        else dp[pos] = i;
        g[i] = dp.size();
    }
    //Calculate answer
    int res = 0;
    for(int i = 1; i <= N; ++i)res = max(res, f[i] + g[i] - 1);
    cout << res << '\n';
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         if(pos == dp.size())
      |            ~~~~^~~~~~~~~~~~
glo.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if(pos == dp.size())
      |            ~~~~^~~~~~~~~~~~
glo.cpp: In function 'void testIO()':
glo.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |     freopen("../test.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 1200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 844 KB Output is correct
2 Correct 12 ms 1356 KB Output is correct
3 Incorrect 12 ms 1288 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -