Submission #1284773

#TimeUsernameProblemLanguageResultExecution timeMemory
1284773HaanhtienGlobal Warming (CEOI18_glo)C++17
38 / 100
28 ms2700 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define FOR(i, a, b) for(int i=(a), _b=(b); i<=_b; i++)
#define FORD(i, a, b) for(int i=(a), _b=(b); i>=_b; i--)
#define BIT(i, j) ((i>>j)&1)
#define pb push_back
#define ii pair<ll, ll>
#define pii pair<ll, ii>
#define all(x) x.begin(), x.end()
#define fi first
#define se second

const ll inf = 1e18;
const ll mod = 1e9+7;
const ll N = 200005;
const ll M = 50005;

int n;
ll x;
int len;
ll f[N], a[N];

void sub1 ()
{
    len = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] > f[len])
        {
            f[++len] = a[i];
        }
        else
        {
            int vt = lower_bound(f, f + len + 1, a[i]) - f;
            f[vt] = a[i];
        }
    }
    cout << len;

}

void sub2 ()
{
    int ans = 0;
    for (int j = n; j >= 1; j--)
    {
        a[j] += x;
        len = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] > f[len])
            {
                f[++len] = a[i];
            }
            else
            {
                int vt = lower_bound(f, f + len + 1, a[i]) - f;
                f[vt] = a[i];
            }
        }
        ans = max(ans, len);
    }
    cout << ans;
}
void solve()
{
    cin >> n >> x;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (x == 0) sub1 ();
    else if (n <= 1000) sub2 ();
    

}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "bseq"
    if(fopen(task".inp", "r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

    solve();
    return 0;
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(task".OUT", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...