Submission #443237

#TimeUsernameProblemLanguageResultExecution timeMemory
443237Haruto810198Global Warming (CEOI18_glo)C++17
0 / 100
2072 ms9668 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d)) #define szof(x) ((int)(x).size()) #define vi vector<int> #define pii pair<int, int> #define F first #define S second #define pb push_back #define eb emplace_back #define mkp make_pair const int INF = 2147483647; const int LNF = INF*INF; const int MOD = 1000000007; const int mod = 998244353; const double eps = 1e-12; const int MAX = 200010; int n, x; int arr[MAX][3]; int dp[MAX][3]; vi qu[3]; void modify(int i, int j, int k){ if(dp[i][j] > szof(qu[k])){ qu[k].pb(arr[i][j]); } else{ qu[k][dp[i][j] - 1] = min(qu[k][dp[i][j] - 1], arr[i][j]); } } int query(int j, int T){ /// find max{dp[i][j]} s.t. arr[i] < T if(qu[j].empty()){ return 0; } if(T <= qu[j][0]){ return 0; } int L = 0, R = szof(qu[j]) - 1, mid; while(L < R){ mid = (L + R + 1) / 2; if(T > qu[j][mid]){ L = mid; } else{ R = mid - 1; } } /// qu[i] : dp = i + 1 return L + 1; } int solve(int d){ //cerr<<"solve("<<d<<") : "<<endl; /// init FOR(j, 0, 2, 1){ qu[j].clear(); } FOR(i, 1, n, 1){ arr[i][1] = arr[i][0] + d; } /// dp FOR(i, 1, n, 1){ FOR(j, 0, 2, 1){ dp[i][j] = query(j, arr[i][j]) + 1; //cerr<<"dp["<<i<<"]["<<j<<"] = "<<dp[i][j]<<"\t"; } //cerr<<endl; FOR(j, 0, 2, 1){ FOR(k, 0, j, 1){ modify(i, k, j); } /* cerr<<"qu["<<j<<"] : "; for(int i : qu[j]){ cerr<<i<<" "; } cerr<<endl; */ } } return max({dp[n][0], dp[n][1], dp[n][2]}); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>x; FOR(i, 1, n, 1){ cin>>arr[i][0]; arr[i][2] = arr[i][0]; } int res = 0; FOR(d, -x, x, 1){ res = max(res, solve(d)); } cout<<res<<'\n'; return 0; }
#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...