답안 #566381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566381 2022-05-22T09:31:27 Z thezomb1e Global Warming (CEOI18_glo) C++17
100 / 100
52 ms 4676 KB
//thatsramen

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)

using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;

//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;

//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> void mins(T& x, T y) {x = min(x, y);}
template<typename T> void maxs(T& x, T y) {x = max(x, y);}
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

//order_of_key(k): number of elements strictly less than k
//find_by_order(k): k-th element in the set

void setPrec() {cout << fixed << setprecision(15);}
void unsyncIO() {cin.tie(0)->sync_with_stdio(0);}
void setIn(string s) {freopen(s.c_str(), "r", stdin);}
void setOut(string s) {freopen(s.c_str(), "w", stdout);}
void setIO(string s = "") {
    unsyncIO(); setPrec();
    if(s.size()) setIn(s + ".in"), setOut(s + ".out");
}

// #define TEST_CASES

void solve() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> lis(n + 1);
    int ans = 0;
    {
        vector<int> dp;
        for (int i = 0; i < n; i++) {
            int j = lower_bound(all(dp), a[i]) - dp.begin();
            if (j == (int) dp.size()) {
                dp.pb(a[i]);
            } else {
                dp[j] = a[i];
            }
            lis[i] = j + 1;
        }
        ans = dp.size();
    }
    vector<int> dp;
    for (int i = n - 1; i >= 0; i--) {
        int j = lower_bound(all(dp), -a[i] + x) - dp.begin();
        maxs(ans, lis[i] + j);
        j = lower_bound(all(dp), -a[i]) - dp.begin();
        if (j == (int) dp.size()) {
            dp.pb(-a[i]);
        } else {
            dp[j] = -a[i];
        }
    }
    cout << ans;
}

int main() {
    setIO();

    int tt = 1;
    #ifdef TEST_CASES
        cin >> tt;
    #endif

    while (tt--)
        solve();

    return 0;
}

Compilation message

glo.cpp: In function 'void setIn(std::string)':
glo.cpp:44:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 | void setIn(string s) {freopen(s.c_str(), "r", stdin);}
      |                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp: In function 'void setOut(std::string)':
glo.cpp:45:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 | void setOut(string s) {freopen(s.c_str(), "w", stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 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 0 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 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 212 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 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 3392 KB Output is correct
2 Correct 51 ms 3816 KB Output is correct
3 Correct 51 ms 3816 KB Output is correct
4 Correct 50 ms 3772 KB Output is correct
5 Correct 43 ms 3888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1140 KB Output is correct
2 Correct 11 ms 1108 KB Output is correct
3 Correct 11 ms 1144 KB Output is correct
4 Correct 10 ms 1232 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 10 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1996 KB Output is correct
2 Correct 22 ms 2068 KB Output is correct
3 Correct 46 ms 3776 KB Output is correct
4 Correct 30 ms 3904 KB Output is correct
5 Correct 14 ms 2136 KB Output is correct
6 Correct 24 ms 3884 KB Output is correct
7 Correct 32 ms 4568 KB Output is correct
8 Correct 27 ms 1996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 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 212 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 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 51 ms 3392 KB Output is correct
28 Correct 51 ms 3816 KB Output is correct
29 Correct 51 ms 3816 KB Output is correct
30 Correct 50 ms 3772 KB Output is correct
31 Correct 43 ms 3888 KB Output is correct
32 Correct 14 ms 1140 KB Output is correct
33 Correct 11 ms 1108 KB Output is correct
34 Correct 11 ms 1144 KB Output is correct
35 Correct 10 ms 1232 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 7 ms 1140 KB Output is correct
38 Correct 10 ms 1108 KB Output is correct
39 Correct 22 ms 1996 KB Output is correct
40 Correct 22 ms 2068 KB Output is correct
41 Correct 46 ms 3776 KB Output is correct
42 Correct 30 ms 3904 KB Output is correct
43 Correct 14 ms 2136 KB Output is correct
44 Correct 24 ms 3884 KB Output is correct
45 Correct 32 ms 4568 KB Output is correct
46 Correct 27 ms 1996 KB Output is correct
47 Correct 31 ms 1972 KB Output is correct
48 Correct 24 ms 1992 KB Output is correct
49 Correct 52 ms 3780 KB Output is correct
50 Correct 32 ms 3928 KB Output is correct
51 Correct 25 ms 3264 KB Output is correct
52 Correct 32 ms 4032 KB Output is correct
53 Correct 27 ms 4020 KB Output is correct
54 Correct 31 ms 4676 KB Output is correct
55 Correct 39 ms 3856 KB Output is correct