Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef LOCAL
- #include <prettyprint.hpp>
- #endif
- #include<bits/stdc++.h>
- #define endl '\n'
- #define all(x) x.begin(), x.end()
- #define rall(x) x.rbegin(), x.rend()
- #define lg2(x) __lg(x)
- #define rem_dupl(x) sort(all(x)); x.erase(unique(all(x)), x.end())
- using namespace std;
- typedef long long ll;
- typedef long double db;
- typedef pair<int,int> ii;
- #define x first
- #define y second
- //mt19937 rand32(chrono::steady_clock::now().time_since_epoch().count());
- //mt19937_64 rand64(chrono::steady_clock::now().time_since_epoch().count());
- const db eps = 1e-9;
- const int maxn = (int)2e5 + 5;
- const ll mod = (int)1e9 + 7; // 998244353
- int par[maxn][2], n;
- db dp[maxn][2], a[maxn];
- bool choosen[maxn];
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0);
- cout.setf(ios::fixed); cout.precision(0);
- cin >> n;
- for(int i = 1; i <= n; i++){
- int x; cin >> x;
- a[i] = log((db)x);
- }
- for(int i = 0; i < 2; i++)
- fill(dp[0], dp[0] + n + 1, LLONG_MIN);
- dp[0][0] = 0;
- for(int i = 0; i < n; i++){
- if(dp[i][0] != LLONG_MIN){
- if(dp[i+1][0] < dp[i][0]){
- dp[i+1][0] = dp[i][0];
- par[i+1][0] = 0;
- }
- if(dp[i+1][1] < dp[i][0] + a[i+1]){
- dp[i+1][1] = dp[i][0] + a[i+1];
- par[i+1][1] = 1;
- }
- }
- if(dp[i][1] != LLONG_MIN){
- if(dp[i][1] > dp[i+1][1]){
- dp[i+1][1] = dp[i][1];
- par[i+1][1] = 0;
- }
- if(dp[i+1][0] < dp[i][1] - a[i+1]){
- dp[i+1][0] = dp[i][1] - a[i+1];
- par[i+1][0] = 1;
- }
- }
- }
- int last = n;
- int f = 0;
- while(last){
- if(par[last][f]){
- choosen[last] = 1;
- f ^= 1;
- }
- last--;
- }
- for(int i = 1; i <= n; i++){
- cout << choosen[i] << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement