답안 #561134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561134 2022-05-12T10:19:17 Z urosk Calvinball championship (CEOI15_teams) C++14
100 / 100
974 ms 652 KB
// __builtin_popcount(x)
// __builtin_popcountll(x)
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;

#define maxn 10005
#define mod 1000007
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
	if(x==mod) x = 0;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
ll n;
ll a[maxn];
ll dp[2][maxn];
ll mx[maxn];
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n;
    for(ll i = 1;i<=n;i++) cin >> a[i];
    for(ll i = 1;i<=n;i++) mx[i] = max(mx[i-1],a[i]);
    for(ll i = 1;i<=n;i++) dp[0][i] = 1;
    ll ans = 1;
    for(ll i = n;i>=1;i--){
        ll e = (n-i+1)&1;
        for(ll j = 1;j<=n;j++) dp[e&1][j] = add(mul(j,dp[e^1][j]),dp[e^1][j+1]);
        ans = add(ans,mul(a[i]-1,dp[e^1][mx[i-1]]));
    }
    cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 456 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 340 KB Output is correct
2 Correct 11 ms 340 KB Output is correct
3 Correct 11 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 927 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 468 KB Output is correct
2 Correct 238 ms 500 KB Output is correct
3 Correct 253 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 974 ms 620 KB Output is correct
2 Correct 940 ms 652 KB Output is correct
3 Correct 954 ms 596 KB Output is correct