답안 #555404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555404 2022-04-30T20:49:38 Z hidden1 Calvinball championship (CEOI15_teams) C++14
100 / 100
914 ms 844 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define endl "\n"

#define out(x) "[" << #x << "=" << x << "]"
struct debug {
    debug() { cerr << "DEBUGGER: " << endl; }
    ~debug() { cerr << endl << "DEBUGGER_END " << endl; }

    template<class T>
    debug& operator <<(const T x) {
        cerr << x << " ";
        return *this;
    }
};

template<class T> inline ostream &operator <<(ostream &out, const vector<T> &x) {
    for(const auto &it : x) {
        out << it << " ";
    }
    return out;
}
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) {
    return out << x.first << " " << x.second;
}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }

typedef long long ll;
const ll mod = 1e6 + 7;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

const ll MAX_N = 2e4 + 10;
ll dp[2][MAX_N];
ll n;
ll arr[MAX_N];

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

    cin >> n;
    for(ll i = 1; i <= n; i ++) {
        cin >> arr[i];
    }

    ll mx = 0;

    for(ll i = 0; i < n; i ++) {
        ll curr = i & 1;
        ll nxt = curr ^ 1;

        for(ll j = 0; j < MAX_N; j ++) {
            dp[nxt][j] = 0;
        }

        for(ll j = 0; j < MAX_N - 1; j ++) {
            dp[nxt][j] += (dp[curr][j] * j) % mod;
            dp[nxt][j] %= mod;
            dp[nxt][j + 1] += dp[curr][j];
            dp[nxt][j + 1] %= mod;
        }

        assert(mx + 1 == arr[i + 1] || mx >= arr[i + 1]);

        dp[nxt][mx] += arr[i + 1] - 1;
        dp[nxt][mx] %= mod;

        chkmax(mx, arr[i + 1]);

        continue;
        cout << i << endl;
        for(ll i = 0; i <= n; i ++) {
            cout << dp[curr][i] << " ";
        }
        cout << endl;
    }

    ll ret = 1;
    for(ll i = 0; i < MAX_N; i ++) {
        ret = (ret + dp[n & 1][i]) % mod;
    }

    cout << ret << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 632 KB Output is correct
2 Correct 10 ms 596 KB Output is correct
3 Correct 11 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 616 KB Output is correct
2 Correct 48 ms 596 KB Output is correct
3 Correct 48 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 632 KB Output is correct
2 Correct 94 ms 636 KB Output is correct
3 Correct 92 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 903 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 596 KB Output is correct
2 Correct 450 ms 672 KB Output is correct
3 Correct 463 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 914 ms 692 KB Output is correct
2 Correct 903 ms 844 KB Output is correct
3 Correct 903 ms 748 KB Output is correct