답안 #362823

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362823 2021-02-04T13:06:49 Z Sparky_09 Calvinball championship (CEOI15_teams) C++17
100 / 100
419 ms 620 KB
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

const ll mod = 1e6 + 7;
const int N = 1e4 + 10;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
  int n, a[N], dp[2][N], mx[N];  
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    mx[i] = max(mx[i-1], a[i]);
  }
  for(int i = 0; i <= n; i++){
    dp[0][i] = 1;
  }
  int ans = a[n], t = 1;
  for(int i = 1; i < n; i++){
  	t = (i%2?1:0);
    for(int j = 1; j <= n; j++){
      dp[t][j] = (dp[t^1][j+1] + 1LL * dp[t^1][j] * j % mod)%mod;
    }
    ans = (ans + 1LL * dp[t][mx[n-i-1]] * (a[n-i]-1)%mod)%mod;
  }
  cout << ans%mod;
}

































Compilation message

teams.cpp: In function 'void usaco(std::string)':
teams.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 396 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 5 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 404 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 620 KB Output is correct
2 Correct 103 ms 492 KB Output is correct
3 Correct 107 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 410 ms 620 KB Output is correct
2 Correct 413 ms 492 KB Output is correct
3 Correct 419 ms 620 KB Output is correct