답안 #251129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251129 2020-07-20T11:49:59 Z Sorting Calvinball championship (CEOI15_teams) C++17
20 / 100
129 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;

const int k_N = 1e4 + 3;
const int k_Mod = 1e9 + 7;

int n, a[k_N];
pair<int, bool> dp[k_N][k_N][2];

int solve(int pos, int cnt, bool equal){
    if(pos == n) return 1;

    auto &[ans, solved] = dp[pos][cnt][equal];
    if(solved) return ans;

    solved = true;
    ans = 0;

    if(!equal){ 
        ans = (((long long)solve(pos + 1, cnt, false)) * (long long)cnt + (long long)solve(pos + 1, cnt + 1, false)) % k_Mod;
        return ans;
    }

    ans = (((long long)solve(pos + 1, cnt, false)) * (long long)min(cnt, a[pos] - 1)) % k_Mod;
    if(a[pos] <= cnt)
        ans += solve(pos + 1, cnt, true);
    else if(a[pos] == cnt + 1)
        ans += solve(pos + 1, cnt + 1, true);
    else if(a[pos] > cnt + 1)
        ans += solve(pos + 1, cnt + 1, false);

    ans %= k_Mod;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> a[i];

    cout << solve(0, 0, true) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 768 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 12544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 85 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 129 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 84 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -