제출 #1125117

#제출 시각아이디문제언어결과실행 시간메모리
1125117vinh1e2kgGlobal Warming (CEOI18_glo)C++20
100 / 100
51 ms2756 KiB
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define ll long long
#define pii pair<int, int>
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define MS(a, v) memset(a, v, sizeof a)
#define REP(i, n) for(int i = 0; i < n; ++ i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++ i)
#define FOD(i, a, b) for(int i = (a); i >= (b); -- i)
#define TSun(TZ) freopen(TZ".inp", "r", stdin), freopen(TZ".out", "w", stdout)

template<class X, class Y>
        bool maximize(X & x, const Y & y){
                if(x < y){
                        x = y;
                        return true;
                }
                else return false;
        }

template<class X, class Y>
        bool minimize(X & x, const Y & y){
                if(x > y){
                        x = y;
                        return true;
                }
                else return false;
        }

const int MAXN = 200005;
const int MOD = 1e9 + 7;
const ll INF = 1e18;

void add(int &a, int b){
        a += b;
        if(a >= MOD) a -= MOD;
}

void sub(int &a, int b){
        a -= b;
        if(a < 0) a += MOD;
}

int sumMOD(int &a, int b){
        return a + b >= MOD ? a + b - MOD : a + b;
}

bool BIT(int mask, int i){
        return (mask >> i & 1);
}

int MASK(int x){
        return (1 << x);
}

int n, x, a[MAXN], f[MAXN], ans;
vector <ll> dp;

void solve(void){
        cin >> n >> x;
        FOR(i, 1, n){
                cin >> a[i];
                auto it = lower_bound(ALL(dp), a[i] + x);
                f[i] = it - dp.begin() + 1;
                it = lower_bound(ALL(dp), a[i]);
                if(it == dp.end())
                        dp.PB(a[i]);
                else
                        *it = a[i];
        }
        dp.clear();
        FOD(i, n, 1){
                auto it = lower_bound(ALL(dp), - a[i]);
                maximize(ans, f[i] + it - dp.begin());
                if(it == dp.end())
                        dp.PB(-a[i]);
                else
                        *it = -a[i];
        }
        cout << ans;
}

int main(void){

        ios_base :: sync_with_stdio(0);
        cin.tie(0); cout.tie(0);

        #define TaZinh "test"

        if(fopen(TaZinh".inp", "r"))
                TSun(TaZinh);

        int Sun = 1;
//        cin >> Sun;
        REP(love, Sun) solve();

        return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int main()':
glo.cpp:16:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define TSun(TZ) freopen(TZ".inp", "r", stdin), freopen(TZ".out", "w", stdout)
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:97:17: note: in expansion of macro 'TSun'
   97 |                 TSun(TaZinh);
      |                 ^~~~
glo.cpp:16:56: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define TSun(TZ) freopen(TZ".inp", "r", stdin), freopen(TZ".out", "w", stdout)
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:97:17: note: in expansion of macro 'TSun'
   97 |                 TSun(TaZinh);
      |                 ^~~~
#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...