Cod sursa(job #3223893)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 14 aprilie 2024 09:20:02
Problema P-sir Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.78 kb
#ifndef LOCAL
    #pragma GCC optimize("O3")
    #pragma GCC target("avx2")
#endif

#ifdef LOCAL
    #define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using ci = const int;
using cll = const long long;

using namespace std;

const int MOD = (1LL << 32);
const int NMAX = 2e3 + 5;
/*******************************/
// INPUT / OUTPUT

#ifndef LOCAL
    ifstream in("psir.in");
    ofstream out("psir.out");
    #define cin in
    #define cout out
#endif
/*******************************/
/// GLOBAL DECLARATIONS

int N;
int sol;
int v[NMAX];
int dp[NMAX][NMAX];
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    cin >> N;

    for (int i = 1 ; i <= N ; ++ i)
        cin >> v[i];
}
///-------------------------------------
inline void Solution()
{
    for (int i = 1 ; i <= N ; ++ i)
    {
        for (int j = i + 1 ; j <= N ; ++ j)
        {
            dp[i][j] = 1;
            for (int k = i - 1 ; k >= 1 ; -- k)
            {
                if ((v[i] > v[j] && v[j] > v[k]) || (v[i] < v[j] && v[j] < v[k]))
                {
                    dp[i][j] += dp[k][i];
                    if (dp[i][j] >= MOD) dp[i][j] -= MOD;
                }
            }

            sol += dp[i][j];
            if (sol >= MOD) sol -= MOD;
        }
    }
}
///-------------------------------------
inline void Output()
{
    cout << sol;
}
///-------------------------------------
signed main()
{
    #ifndef LOCAL
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    #endif
    ReadInput();
    Solution();
    Output();
    return 0;
}