답안 #82422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82422 2018-10-30T14:06:01 Z AngelKnows Calvinball championship (CEOI15_teams) C++14
80 / 100
1000 ms 892 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];
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;
		}
		
		int res=0;
		
		if (a[i]>1) {
			if (tot==pre) FOR(j,n-i+1) {
				if (tot+1<=n) res+=(ll)g[tot%2][j-1]%mo*f[n-i-j+1][(tot+1)%2]%mo,res%=mo;
				else if (j==n-i+1) res+=(ll)g[tot%2][j-1]%mo*1%mo,res%=mo;
			} else {
				FOR(j,n-i+1) {
					res+=(ll)g[pre%2][j-1]%mo*f[n-i-j+1][tot%2]%mo,res%=mo;
				}
			}
		}
		//cout<<res<<endl;
		ans+=(ll)res*(a[i]-1)%mo;
		ans%=mo;
	}
	ans=(ans+1)%mo;
	printf("%d\n",ans);
	return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
teams.cpp:37: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]);
              ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 532 KB Output is correct
4 Correct 2 ms 532 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 544 KB Output is correct
2 Correct 2 ms 676 KB Output is correct
3 Correct 2 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 724 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 8 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 764 KB Output is correct
2 Correct 19 ms 764 KB Output is correct
3 Correct 24 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 764 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 398 ms 764 KB Output is correct
2 Correct 396 ms 764 KB Output is correct
3 Correct 563 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 892 KB Time limit exceeded
2 Halted 0 ms 0 KB -