제출 #882138

#제출 시각아이디문제언어결과실행 시간메모리
882138skywwlaGlobal Warming (CEOI18_glo)C++17
0 / 100
2032 ms3292 KiB
#include <bits/stdc++.h> using namespace std ; using ll = long long ; const int N = 2e5 + 5 ; int n , x , a[N], l[N], r[N] ; int findLIS() { vector<int> d ; for (int i = 1 ; i <= n ; i++) { auto it = upper_bound(d.begin(), d.end(), a[i]) ; if (it == d.end()) d.push_back(a[i]) ; else *it = a[i] ; } return d.size() ; } int32_t main() { ios::sync_with_stdio(false) ; cin.tie(nullptr) ; cin >> n >> x ; for (int i = 1 ; i <= n ; i++) { cin >> a[i] ; } for (int i = 1 ; i <= n ; i++) { l[i] = a[i] - x ; r[i] = a[i] + x ; } int ret = findLIS() ; if (!x) { cout << ret ; return 0 ; } vector<int> dp ; for (int i = 1 ; i <= n ; i++) { auto it = lower_bound(dp.begin(), dp.end(), a[i]) ; int mx = it - dp.begin() + 1 ; if (it == dp.end()) dp.push_back(a[i]) ; else *it = a[i] ; deque<int> dp1 ; for (int j = n ; j > i ; j--) { auto it1 = lower_bound(dp1.begin(), dp1.end(), a[j]) ; int pos = it1 - dp1.begin() + 1 ; if (it1 == dp1.begin()) dp1.push_front(a[j]) ; else { it1-- ; *it1 = a[j] ; } int cur = it1 - dp1.begin() + 1 ; if (a[j] - 1 >= l[i] && a[j] - 1 <= r[i]) { // cout << mx + cur << "\n" ; // cout << mx << ' ' << l[i] << ' ' << r[i] << ' ' << i << ' ' << dp1.size() << ' ' << j << "\n" ; ret = max(ret, mx + cur) ; } } } cout << ret ; return 0 ; }

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

glo.cpp: In function 'int32_t main()':
glo.cpp:45:17: warning: unused variable 'pos' [-Wunused-variable]
   45 |             int pos = it1 - dp1.begin() + 1 ;
      |                 ^~~
#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...