답안 #113925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113925 2019-05-29T08:39:38 Z Mercenary Calvinball championship (CEOI15_teams) C++14
100 / 100
309 ms 692 KB
#include<bits/stdc++.h>

using namespace std;
#define taskname "A"
#define pb  push_back
#define mp  make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 1e4 + 5;
const int mod = 1e6 + 7;

int a[maxn] , ma[maxn];

int dp[2][maxn];
int n;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin);
        freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    for(int i = 1 ; i <= n ; ++i)ma[i] = max(ma[i - 1] , a[i]);
    int res = 1;bool bit = 0;
    for(int j = 0 ; j <= n ; ++j){
        dp[0][j] = 1;
    }
    for(int i = n ; i >= 1 ; --i){
//        res += (ll)(a[i] - 1) * dp[bit][ma[i - 1]] % mod;
//        cout << i << " " << dp[bit][ma[i]] << endl;
        if(res >= mod)res -= mod;
        bit ^= 1;
        for(int j = 1 ; j <= n ; ++j){
            dp[bit][j] = dp[bit ^ 1][j + 1] + (ll)j * dp[bit ^ 1][j] % mod;
            if(dp[bit][j] >= mod)dp[bit][j] -= mod;
            if(j < a[i]){
                res += dp[bit ^ 1][max(ma[i - 1],j)];
                if(res >= mod)res -= mod;
//                cout << i << " " << max(ma[i - 1] , )
            }
        }
    }
    cout << res;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 297 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 528 KB Output is correct
2 Correct 66 ms 512 KB Output is correct
3 Correct 80 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 256 ms 568 KB Output is correct
2 Correct 251 ms 604 KB Output is correct
3 Correct 309 ms 692 KB Output is correct