답안 #95895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95895 2019-02-03T12:21:18 Z popovicirobert Calvinball championship (CEOI15_teams) C++14
100 / 100
442 ms 632 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MOD = (int) 1e6 + 7;
const int MAXN = 10005;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

int arr[MAXN + 1], mx[MAXN + 1];
int dp[2][MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
        mx[i] = max(mx[i - 1], arr[i]);
    }
    for(i = 1; i <= n; i++) {
        dp[n & 1][i] = 1;
        //cerr << 1 << " ";
    }
    //cerr << "\n";
    int ans = arr[n] - 1;
    for(i = n - 1; i >= 1; i--) {
        int sum = 0;
        for(j = 1; j <= n; j++) {
            dp[i & 1][j] = (dp[1 - i & 1][j + 1] + sum + 1LL * dp[1 - i & 1][j] * (j - (j > 1))) % MOD;
            sum += dp[1 - i & 1][j];
            mod(sum);
            //cerr << dp[i & 1][j] << " ";
        }
        //cerr << "\n";
        int cur = 0;
        for(j = 1; j <= mx[i - 1] + 1; j++) {
            cur += dp[1 - i & 1][j];
            mod(cur);
        }
        //cerr << dp[1 - i & 1][mx[i - 1]] << " " << dp[1 - i & 1][mx[i - 1] + 1] << "\n\n";
        ans = (ans + 1LL * cur * (arr[i] - 1)) % MOD;
    }
    cout << (ans + 1) % MOD;
    //cin.close();
    //cout.close();
    return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:42:34: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
             dp[i & 1][j] = (dp[1 - i & 1][j + 1] + sum + 1LL * dp[1 - i & 1][j] * (j - (j > 1))) % MOD;
                                ~~^~~
teams.cpp:42:69: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
             dp[i & 1][j] = (dp[1 - i & 1][j + 1] + sum + 1LL * dp[1 - i & 1][j] * (j - (j > 1))) % MOD;
                                                                   ~~^~~
teams.cpp:43:25: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
             sum += dp[1 - i & 1][j];
                       ~~^~~
teams.cpp:50:25: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
             cur += dp[1 - i & 1][j];
                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 292 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 504 KB Output is correct
2 Correct 78 ms 488 KB Output is correct
3 Correct 92 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 536 KB Output is correct
2 Correct 306 ms 568 KB Output is correct
3 Correct 442 ms 632 KB Output is correct