Submission #1052191

# Submission time Handle Problem Language Result Execution time Memory
1052191 2024-08-10T12:23:10 Z Phuoc Money (IZhO17_money) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set> 

using namespace std;
 
#define ll long long
#define pb push_back
#define el '\n'
#define mpair make_pair
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define fi first
#define se second
#define all(v) v.begin(), v.end()
 
/* Author: Pham Gia Phuoc */
 
const ll MOD = (ll)(1e9) + 7LL;
 
template <class T1, class T2>
    void add(T1 &a, T2 b){
        a += b;
        if(a >= MOD) a -= MOD;
    }
 
template <class T1, class T2>
    void sub(T1 &a, T2 b){
        a -= b;
        if(a < 0) a += MOD;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if(a > b){a = b; return true;} return false;
    }
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if(a < b){a = b; return true;} return false;
    }
 
/** END OF TEMPLATE. DRINK A CUP OF COFFEE BEFORE READING MY CODE **/
 
const int MAX = (int)(1e6) + 10;
const ll INF = (ll) 1e18 + 67LL;
const int oo = (int)(1e9 + 7);
const int NUM_BIT = 62;

#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)

int n, a[MAX];

void init(){
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
}

namespace subtask1{
    bool check(){
        return n <= 1e3;
    }

    const int MAXN = (int)(1e3) + 10;
    vector <int> cur[MAXN];
    int dp[MAXN];    

    void solve(){
        FOR(i, 1, n){
            FOR(j, 1, i){
                cur[i].push_back(j);
            }   
            sort(cur[i].begin(), cur[i].end());
            cur[i].resize(unique(cur[i].begin(), cur[i].end()) - cur[i].begin());
        }
    
        dp[0] = 0;
        FOR(i, 1, n){
            dp[i] = dp[i - 1] + 1;
            FORD(j, i - 1, 1){
                if(a[j] > a[j + 1]) break;
                if(a[j] == a[i]){
                    minimize(dp[i], dp[j - 1] + 1);
                    continue;
                }
                int cnt = upper_bound(cur[j - 1].begin(), cur[j - 1].end(), a[i] - 1) - lower_bound(cur[j - 1].begin(), cur[j - 1].end(), a[j] + 1);
                if(cnt != 0) continue;
                minimize(dp[i], dp[j - 1] + 1);
            }
        }
        cout << dp[n];
    }
}

void solve(){  
    if(subtask1::check()){subtask1::solve(); return;}
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define test "test"
    // freopen(test".inp", "r", stdin);
    // freopen(test".out", "w", stdout);
    srand(time(0));
    int t = 1;
    while(t--){
        init();
        solve();
    }
    return 0;
}
 
 
 
/*** ROAD TO VOI 2025 ***/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -