답안 #552923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552923 2022-04-24T10:13:05 Z Soul234 Global Warming (CEOI18_glo) C++14
100 / 100
53 ms 4328 KB
#include<bits/stdc++.h>
using namespace std;

void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;

void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(NAME)) {
        freopen((NAME + ".in").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

const int MX = 2e5+5;
int N, X, A[MX], R[MX], ans;

void solve() {
    cin>>N>>X;
    F0R(i,N) cin>>A[i];
    vi v;
    R0F(i,N) {
        int p = lower_bound(all(v), -A[i]) - begin(v);
        if(p == sz(v)) v.pb(-A[i]);
        else v[p] = -A[i];
        R[i] = p;
    }
    v.clear();
    F0R(i,N) {
        int p = lower_bound(all(v), A[i]) - begin(v);
        ans = max(ans, R[i] + 1 + p);
        p = lower_bound(all(v), A[i] - X) - begin(v);
        if(p == sz(v)) v.pb(A[i] - X);
        else v[p] = A[i] - X;
    }
    cout << ans << nl;
}

int main() {
    setIO();

    int t=1;
    //cin>>t;
    while(t-->0) {
        solve();
    }

    return 0;
}

Compilation message

glo.cpp: In function 'void setIO(std::string)':
glo.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 3796 KB Output is correct
2 Correct 51 ms 3712 KB Output is correct
3 Correct 52 ms 3736 KB Output is correct
4 Correct 51 ms 3784 KB Output is correct
5 Correct 30 ms 3524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1092 KB Output is correct
2 Correct 13 ms 1092 KB Output is correct
3 Correct 11 ms 1128 KB Output is correct
4 Correct 8 ms 1236 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1108 KB Output is correct
7 Correct 12 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2036 KB Output is correct
2 Correct 26 ms 1976 KB Output is correct
3 Correct 46 ms 3776 KB Output is correct
4 Correct 30 ms 3532 KB Output is correct
5 Correct 14 ms 2008 KB Output is correct
6 Correct 24 ms 3536 KB Output is correct
7 Correct 26 ms 4148 KB Output is correct
8 Correct 19 ms 2000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 50 ms 3796 KB Output is correct
28 Correct 51 ms 3712 KB Output is correct
29 Correct 52 ms 3736 KB Output is correct
30 Correct 51 ms 3784 KB Output is correct
31 Correct 30 ms 3524 KB Output is correct
32 Correct 12 ms 1092 KB Output is correct
33 Correct 13 ms 1092 KB Output is correct
34 Correct 11 ms 1128 KB Output is correct
35 Correct 8 ms 1236 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 8 ms 1108 KB Output is correct
38 Correct 12 ms 1108 KB Output is correct
39 Correct 24 ms 2036 KB Output is correct
40 Correct 26 ms 1976 KB Output is correct
41 Correct 46 ms 3776 KB Output is correct
42 Correct 30 ms 3532 KB Output is correct
43 Correct 14 ms 2008 KB Output is correct
44 Correct 24 ms 3536 KB Output is correct
45 Correct 26 ms 4148 KB Output is correct
46 Correct 19 ms 2000 KB Output is correct
47 Correct 26 ms 1968 KB Output is correct
48 Correct 26 ms 2080 KB Output is correct
49 Correct 53 ms 3756 KB Output is correct
50 Correct 30 ms 3440 KB Output is correct
51 Correct 24 ms 2876 KB Output is correct
52 Correct 31 ms 3592 KB Output is correct
53 Correct 26 ms 3668 KB Output is correct
54 Correct 32 ms 4328 KB Output is correct
55 Correct 43 ms 3788 KB Output is correct