Submission #26239

# Submission time Handle Problem Language Result Execution time Memory
26239 2017-06-28T13:15:41 Z Kerim Calvinball championship (CEOI15_teams) C++14
0 / 100
0 ms 2332 KB
#include "bits/stdc++.h"
#define MAXN 10009
#define INF 1000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dp[2][MAXN],n;
vector<PII>add[MAXN];
int mod(ll x){
	return (x%INF);
}
int main(){
	#ifndef ONLINE_JUDGE
    freopen("file.in", "r", stdin);
	#endif	
	scanf("%d",&n);int cnt=0,ans=1;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		add[i+1].pb(mp(cnt,min(x-1,cnt)));
		if(cnt+1<x)
			add[i+1].pb(mp(cnt+1,1));
		if(cnt+1==x)
			cnt++;
	}
	for(int i=0;i<=n;i++)
		dp[(n+1)&1][i]=1;
	tr(it,add[n+1])
		ans=mod(ans+mod(dp[(n+1)&1][it->ff]*1LL*it->ss));	
	for(int i=n;i>1;i--){
		for(int j=0;j<=n;j++){
			dp[i&1][j]=dp[(i&1)^1][j+1];
			dp[i&1][j]=mod(dp[i&1][j]+mod(dp[(i&1)^1][j]*1LL*j));
		}
		tr(it,add[i])
			ans=mod(ans+mod(dp[i&1][it->ff]*1LL*it->ss));
	}	
	printf("%d\n",ans);
	return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:27:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("file.in", "r", stdin);
                                   ^
teams.cpp:29:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);int cnt=0,ans=1;
                ^
teams.cpp:32:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
                 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2332 KB Output is correct
2 Incorrect 0 ms 2332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2332 KB Output is correct
2 Incorrect 0 ms 2332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -