Submission #82463

# Submission time Handle Problem Language Result Execution time Memory
82463 2018-10-30T23:59:36 Z AngelKnows Calvinball championship (CEOI15_teams) C++14
100 / 100
537 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];
bool fi[N];
int mx[N];
int dp[2][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 pos,tot;
	FOR(i,n) {
		pos=n+1-i;
		tot=mx[pos];
		if (i==1) {
			FOR(j,n) dp[i&1][j]=1;
		} else {
			FOR(j,n) dp[i&1][j]=dp[1-(i&1)][j+1]%mo+(ll)j*dp[1-(i&1)][j]%mo,dp[i&1][j]%=mo;
		}
		if (fi[pos]) ans+=(ll)(a[pos]-1)*dp[i&1][tot-1]%mo;
		else ans+=(ll)(a[pos]-1)*dp[i&1][tot]%mo;
		//cout<<pos<<" "<<ans<<endl;
		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]);
              ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 520 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 644 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 644 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 644 KB Output is correct
2 Correct 3 ms 644 KB Output is correct
3 Correct 3 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 672 KB Output is correct
2 Correct 16 ms 764 KB Output is correct
3 Correct 7 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 494 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 804 KB Output is correct
2 Correct 130 ms 804 KB Output is correct
3 Correct 135 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 531 ms 808 KB Output is correct
2 Correct 537 ms 808 KB Output is correct
3 Correct 531 ms 892 KB Output is correct