답안 #527687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527687 2022-02-18T03:01:29 Z jamielim Calvinball championship (CEOI15_teams) C++14
100 / 100
89 ms 628 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

const int mod=1000007;
int n;
ll arr[10005];
ll premax[10005];
ll dp[2][10005];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&arr[i]);
		if(i==0)premax[i]=arr[i];
		else premax[i]=max(premax[i-1],arr[i]);
	}
	ll ans=1; // all equal (final day)
	for(int i=1;i<=n-1;i++){
		dp[(n-1)&1][i]=1;
	}
	ans+=(arr[n-1]-1)*dp[(n-1)&1][premax[n-2]];
	ans%=mod;
	//printf("%lld\n",ans);
	for(int i=n-2;i>=1;i--){
		for(int j=1;j<=i;j++){
			dp[i&1][j]=(ll)(j)*dp[(i+1)&1][j]+dp[(i+1)&1][j+1];
			dp[i&1][j]%=mod;
		}
		ans+=(arr[i]-1)*dp[i&1][premax[i-1]];
		ans%=mod;
		//printf("%lld\n",ans);
	}
	printf("%lld",ans);
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
teams.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%lld",&arr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 484 KB Output is correct
2 Correct 23 ms 460 KB Output is correct
3 Correct 22 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 620 KB Output is correct
2 Correct 86 ms 588 KB Output is correct
3 Correct 88 ms 588 KB Output is correct