Submission #82423

# Submission time Handle Problem Language Result Execution time Memory
82423 2018-10-30T14:31:44 Z AngelKnows Calvinball championship (CEOI15_teams) C++14
70 / 100
1000 ms 888 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 u,v,t; 
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--) {
		u=i%2,v=(i+1)%2;
		f[1][u]=1;
		REP(j,2,n) f[j][u]=(f[j-1][v]%mo+i*f[j-1][u]%mo)%mo;
	}
	u=tot%2;
	g[u][0]=1;
	FOR(i,n) g[u][i]=(ll)g[u][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;
		*/
		u=tot%2;
		v=(tot-1)%2;
		t=(tot+1)%2; 
		if (i==n||mx[i]!=mx[i+1]) {
			g[v][0]=1;
			FOR(i,n) g[v][i]=(ll)g[v][i-1]*(tot-1)%mo;
			
			f[1][u]=1;
			REP(i,2,n) f[i][u]=(f[i-1][t]%mo+tot*f[i-1][u]%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[u][j-1]%mo*f[n-i-j+1][t]%mo,dp[i]%=mo;
				else if (j==n-i+1) dp[i]+=(ll)(a[i]-1)*g[u][j-1]%mo%mo,dp[i]%=mo;
			} else {
				t=pre%2;
				FOR(j,n-i+1) {
					dp[i]+=(ll)(a[i]-1)*g[t][j-1]%mo*f[n-i-j+1][u]%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

teams.cpp: In function 'int main()':
teams.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
teams.cpp:39: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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 540 KB Output is correct
2 Correct 2 ms 668 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 728 KB Output is correct
2 Correct 2 ms 728 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 728 KB Output is correct
2 Correct 2 ms 728 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 728 KB Output is correct
2 Correct 6 ms 728 KB Output is correct
3 Correct 8 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 728 KB Output is correct
2 Correct 17 ms 728 KB Output is correct
3 Correct 23 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 888 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 361 ms 888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 888 KB Time limit exceeded
2 Halted 0 ms 0 KB -