Submission #82421

#TimeUsernameProblemLanguageResultExecution timeMemory
82421AngelKnowsCalvinball championship (CEOI15_teams)C++14
80 / 100
1081 ms1028 KiB
#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; } g[tot%2][0]=1; FOR(i,n) g[tot%2][i]=(ll)g[tot%2][i-1]*tot%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; */ if (i==n||mx[i]!=mx[i+1]) { 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 (stderr)

teams.cpp: In function 'int main()':
teams.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
teams.cpp:38:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     FOR(i,n) scanf("%d",&a[i]);
              ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...