Submission #314978

# Submission time Handle Problem Language Result Execution time Memory
314978 2020-10-21T19:01:05 Z mohamedsobhi777 Calvinball championship (CEOI15_teams) C++14
70 / 100
40 ms 16640 KB
#include <bits/stdc++.h>

#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 1000 + 7, mod = 1e6 + 7;
const ll inf = 2e18;

// How interesting!

int n;
int a[N];
int Max;
int c[N][N];
int bit[N];

void add(int x)
{
        for (; x < N; x += x & -x)
                bit[x]++;
}
int get(int x)
{
        int ret = 0;
        for (; x; x -= x & -x)
                ret += bit[x];
        return ret;
}

int mul(int x, int y) { return 1ll * x * y % mod; }
int add(int x, int y) { return (x + y) >= mod ? x + y - mod : x + y; }

void nSr()
{
        c[0][0] = 1;
        for (int i = 1; i < N; ++i)
        {
                for (int j = 0; j <= i; ++j)
                {
                        if (i == j || !j)
                                c[i][j] = 1;
                        else
                                c[i][j] = add(c[i - 1][j - 1], mul(j, c[i - 1][j]));
                }
        }
}

int dp[N][N];

int solve(int x, int y)
{
        if (!x)
                return 1;
        if (~dp[x][y])
                return dp[x][y];
        return dp[x][y] = add(solve(x - 1, y + 1), mul(y, solve(x - 1, y)));
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        memset(dp, -1, sizeof dp);
        //freopen("in.in", "r", stdin);
        nSr();
        cin >> n;
        int ans = 0;
        for (int i = 0; i < n; ++i)
        {
                int x;
                cin >> x;
                if (++a[x] == 1)
                        add(x);
                int sum = 0;
                for (int j = 1; j < x; ++j)
                {
                        ans += solve(n - i - 1, max(j, Max));
                        ans %= mod;
                }
                Max = max(Max, x);
        }
        cout << add(ans, 1);
        return 0;
}

/*
        - bounds sir (segtree = 4N, eulerTour = 2N, ...)
        - a variable defined twice?
        - will overflow?
        - is it a good complexity?
        - don't mess up indices (0-indexed vs 1-indexed)
        - reset everything between testcases. 
*/

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:88:21: warning: unused variable 'sum' [-Wunused-variable]
   88 |                 int sum = 0;
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8320 KB Output is correct
3 Correct 6 ms 8320 KB Output is correct
4 Correct 40 ms 8320 KB Output is correct
5 Correct 6 ms 8320 KB Output is correct
6 Correct 6 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 6 ms 8320 KB Output is correct
3 Correct 6 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 8 ms 8352 KB Output is correct
3 Correct 6 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8320 KB Output is correct
2 Correct 7 ms 8320 KB Output is correct
3 Correct 7 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8448 KB Output is correct
2 Correct 8 ms 8320 KB Output is correct
3 Correct 8 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8320 KB Output is correct
2 Correct 12 ms 8320 KB Output is correct
3 Correct 14 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 16640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 16512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 16604 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -