# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82420 | 2018-10-30T13:57:52 Z | AngelKnows | Calvinball championship (CEOI15_teams) | C++14 | 1000 ms | 1004 KB |
#include <bits/stdc++.h> using namespace std; #define FOR(i,n) for (int i=1;i<=n;i++) #define REP(i,a,b) for (int i=a;i<=b;i++) #define pb push_back #define fi first #define se second #define pi pair<int,int> #define mp make_pair #define sz(x) ((int)(x).size()) typedef long long ll; const int inf=0x3f3f3f3f; const ll linf=1e18; const int N=10000+1; const double eps=1e-5; const int mo=1e6+7; int n; int a[N]; int g[2][N]; int f[N][2]; int dp[N]; bool fi[N]; int mx[N]; int ans; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%d",&n); FOR(i,n) scanf("%d",&a[i]); FOR(i,n) { mx[i]=mx[i-1]; if (a[i]>mx[i]) { fi[i]=1; mx[i]=a[i]; } } int tot,pre; f[0][1]=f[0][0]=1; tot=mx[n]; for (int i=n;i>=tot+1;i--) { f[1][i%2]=1; REP(j,2,n) f[j][i%2]=((ll)f[j-1][(i+1)%2]%mo+(ll)i*f[j-1][i%2]%mo)%mo; } for (int i=n;i>=1;i--) { tot=mx[i]; pre=tot; if (fi[i]) pre--; g[tot%2][0]=1; FOR(i,n) g[tot%2][i]=(ll)g[tot%2][i-1]*tot%mo; g[(tot-1)%2][0]=1; FOR(i,n) g[(tot-1)%2][i]=(ll)g[(tot-1)%2][i-1]*(tot-1)%mo; f[1][tot%2]=1; REP(i,2,n) f[i][tot%2]=((ll)f[i-1][(tot+1)%2]%mo+(ll)tot*f[i-1][tot%2]%mo)%mo; if (a[i]>1) { if (tot==pre) FOR(j,n-i+1) { if (tot+1<=n) dp[i]+=(ll)(a[i]-1)*g[tot%2][j-1]%mo*f[n-i-j+1][(tot+1)%2]%mo,dp[i]%=mo; else if (j==n-i+1) dp[i]+=(ll)(a[i]-1)*g[tot%2][j-1]%mo*1%mo,dp[i]%=mo; } else { FOR(j,n-i+1) { dp[i]+=(ll)(a[i]-1)*g[pre%2][j-1]%mo*f[n-i-j+1][tot%2]%mo,dp[i]%=mo; } } } //cout<<dp[i]<<endl; ans+=dp[i]; ans%=mo; } ans=(ans+1)%mo; printf("%d\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 436 KB | Output is correct |
3 | Correct | 2 ms | 436 KB | Output is correct |
4 | Correct | 2 ms | 436 KB | Output is correct |
5 | Correct | 2 ms | 464 KB | Output is correct |
6 | Correct | 2 ms | 524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 524 KB | Output is correct |
2 | Correct | 2 ms | 564 KB | Output is correct |
3 | Correct | 2 ms | 592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 592 KB | Output is correct |
2 | Correct | 2 ms | 592 KB | Output is correct |
3 | Correct | 3 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 608 KB | Output is correct |
2 | Correct | 2 ms | 608 KB | Output is correct |
3 | Correct | 2 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 608 KB | Output is correct |
2 | Correct | 13 ms | 608 KB | Output is correct |
3 | Correct | 11 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 736 KB | Output is correct |
2 | Correct | 46 ms | 748 KB | Output is correct |
3 | Correct | 36 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1076 ms | 1004 KB | Time limit exceeded |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1078 ms | 1004 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1073 ms | 1004 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |