답안 #477278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477278 2021-10-01T14:40:13 Z Shogun3103 Global Warming (CEOI18_glo) C++17
100 / 100
75 ms 8176 KB
#include <bits/stdc++.h>
 
using namespace std;

#define ll long long
#define ld long double
#define FOR(i,a,b) for(__typeof(b) i=a; i<=b; i++)
#define FOD(i,a,b) for(__typeof(b) i=b; i>=a; i--)
#define EACH(u, v) for(auto& u : v)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,ii>
#define f first
#define s second
#define ed "\n"
#define sp " "
#define vi vector<int>
#define vii vector<ii>
#define vl vector<ll>
#define NO cout << "NO" << ed;
#define YES cout << "YES" << ed;
#define no cout << "no" << ed;
#define yes cout << "yes" << ed;

void setIO(string fileName = ""){
    if(fileName.length()){
        freopen((fileName+".in").c_str(), "r", stdin);
        freopen((fileName+".out").c_str(), "w", stdout);
    }
}

int lnds(vl a)
{
    vi calc;
    for(int q : a) {
        int pos = upper_bound(all(calc), q) - calc.begin();
        if(pos == sz(calc)) calc.pb(q);
        else calc[pos] = q;
    }
    return sz(calc);
}

const int oo1 = 1e9 + 7;
const int oo2 = 1e9 + 9;
const int d4x[] = {0, 0, 1, -1};
const int d4y[] = {1, -1, 0, 0};
const int d8x[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int d8y[] = {1, 1, 1, 0, 0, -1, -1, -1};
const int N = 2e5 + 10;
const int M = 5e3 + 10;
vi adj[N];

int n, m;
int a[N], x, pre[N];

void solve()
{
    cin >> n >> x;
    FOR(i, 1, n) cin >> a[i];

    //left
    int ans = 0;
    vi dp(n, oo1);
    FOR(i, 1, n) {
        int j = lower_bound(all(dp), a[i]) - dp.begin();
        dp[j] = a[i];
        pre[i] = j + 1;
        ans = max(ans, pre[i]);
    }   
    //right
    dp = vi(n, oo1);
    FOD(i, 1, n) {
        int j = lower_bound(all(dp), -a[i] + x) - dp.begin();
        ans = max(ans, pre[i] + j);
        int jj = lower_bound(all(dp), -a[i]) - dp.begin();
        dp[jj] = -a[i];
    }   
    cout << ans;  
}          

int main()
{ 
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);        
    setIO("");
    int t; t = 1;
    //int t; cin >> t;
    FOR(i, 1, t) solve();
    return 0;
}

Compilation message

glo.cpp: In function 'void setIO(std::string)':
glo.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((fileName+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen((fileName+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4972 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 3 ms 4940 KB Output is correct
26 Correct 4 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 8096 KB Output is correct
2 Correct 63 ms 8132 KB Output is correct
3 Correct 60 ms 8028 KB Output is correct
4 Correct 75 ms 8076 KB Output is correct
5 Correct 48 ms 8088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5708 KB Output is correct
2 Correct 17 ms 5780 KB Output is correct
3 Correct 16 ms 5724 KB Output is correct
4 Correct 14 ms 5724 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 13 ms 5812 KB Output is correct
7 Correct 13 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 6496 KB Output is correct
2 Correct 28 ms 6476 KB Output is correct
3 Correct 58 ms 8060 KB Output is correct
4 Correct 45 ms 8124 KB Output is correct
5 Correct 24 ms 6592 KB Output is correct
6 Correct 40 ms 7856 KB Output is correct
7 Correct 45 ms 7952 KB Output is correct
8 Correct 26 ms 6520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4972 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 3 ms 4940 KB Output is correct
26 Correct 4 ms 4940 KB Output is correct
27 Correct 66 ms 8096 KB Output is correct
28 Correct 63 ms 8132 KB Output is correct
29 Correct 60 ms 8028 KB Output is correct
30 Correct 75 ms 8076 KB Output is correct
31 Correct 48 ms 8088 KB Output is correct
32 Correct 16 ms 5708 KB Output is correct
33 Correct 17 ms 5780 KB Output is correct
34 Correct 16 ms 5724 KB Output is correct
35 Correct 14 ms 5724 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 13 ms 5812 KB Output is correct
38 Correct 13 ms 5724 KB Output is correct
39 Correct 28 ms 6496 KB Output is correct
40 Correct 28 ms 6476 KB Output is correct
41 Correct 58 ms 8060 KB Output is correct
42 Correct 45 ms 8124 KB Output is correct
43 Correct 24 ms 6592 KB Output is correct
44 Correct 40 ms 7856 KB Output is correct
45 Correct 45 ms 7952 KB Output is correct
46 Correct 26 ms 6520 KB Output is correct
47 Correct 32 ms 6560 KB Output is correct
48 Correct 35 ms 6508 KB Output is correct
49 Correct 64 ms 8068 KB Output is correct
50 Correct 48 ms 8020 KB Output is correct
51 Correct 37 ms 7372 KB Output is correct
52 Correct 45 ms 8108 KB Output is correct
53 Correct 42 ms 8176 KB Output is correct
54 Correct 48 ms 8032 KB Output is correct
55 Correct 62 ms 8108 KB Output is correct