Submission #1258890

#TimeUsernameProblemLanguageResultExecution timeMemory
1258890khanhdangiuuBoat (APIO16_boat)C++20
0 / 100
1 ms324 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pi 3.14159265358979323846 
#define pb push_back
#define ar array

template<typename T, typename cmp = std::greater<T>>
using pq = priority_queue<T, vector<T>, cmp>;

template<typename T, typename cmp = std::less<T>>
using ordered_set = tree<T, __gnu_pbds::null_type, cmp, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

void chay()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define task "Hi"
    freopen(task".INP", "r", stdin);
    freopen(task".OUT", "w", stdout);
}

const int N = 500, INF = numeric_limits<int>::max();
const int block = 600;
const long long INFLL = numeric_limits<ll>::max();
long long M = 1e9+7;

int n, a[N+5], b[N+5];

namespace sub1
{

    bool check()
    {
        bool ok = true;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] != b[i]) ok = false;
        }
        return n <= 500 && ok;
    }

    int dp[N+5], dpn[N+5];

    void solve()
    {
        dp[0] = dpn[n+1] = 1;
        a[n+1] = INF;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (a[i] > a[j]) dp[i] += dp[j];
                if (dp[i] >= M) dp[i] -= M;
            }
        }

        for (int i = n; i >= 1; i--)
        {
            for (int j = i+1; j <= n+1; j++)
            {
                if (a[i] < a[j]) dpn[i] += dpn[j];
                if (dpn[i] >= M) dpn[i] -= M;
            }
        }

        int tong = 0;
        for (int i = 1; i <= n; i++)
        {
            tong += (ll)dp[i]*dpn[i]%M;
            if (tong >= M) tong -= M;
        }
        cout<<tong;
    }
}

void solve()
{
    cin>>n;
    for (int i = 1; i <= n; i++) cin>>a[i]>>b[i];

    if (sub1::check()) sub1::solve();
}
 
signed main ()
{
    //chay();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;   
    //cin>>t; 
    while (t--)
    {
        solve();
    }

    return 0;
}

Compilation message (stderr)

boat.cpp: In function 'void chay()':
boat.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen(task".INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen(task".OUT", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...