답안 #943155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943155 2024-03-11T08:47:04 Z vjudge1 Fibonacci representations (CEOI18_fib) C++17
15 / 100
4000 ms 1364 KB
#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

vector <int> Delete(vector <int> v, int j) {
    vector <int> res;
    for (int i = 0; i < v.size(); i++) {
        if (i == j) continue;
        res.push_back(v[i]);
    }
    return res;
} 

int main() {
    int n;
    cin >> n;
    
    vector <int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    vector <int> vec;
    for (int i = 1; i <= n; i++) {
        vec.push_back(a[i]);
        while (true) {
            sort(vec.begin(), vec.end());
            if (vec.size() > 1 && vec[0] == vec[1] && vec[0] == 1) {
                vec.push_back(2);
                vec = Delete(vec, 1);
                vec = Delete(vec, 0);
                continue;
            }
            bool repeat = 0;
            for (int i = 1; i < vec.size(); i++) {
                if (vec[i] == vec[i - 1] + 1) {
                    vec.push_back(vec[i] + 1);
                    vec = Delete(vec, i);
                    vec = Delete(vec, i - 1);
                    repeat = 1;
                    break;
                }
            }
            if (!repeat) break;
        }
        sort(vec.begin(), vec.end());
        int sz = (int)vec.size();
        int dp[sz][2];
        dp[0][0] = 1;
        dp[0][1] = (vec[0] - 1) / 2;
        for (int i = 1; i < sz; i++) {
            if (vec[i - 1] != vec[i])
                dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
            else 
                dp[i][0] = dp[i - 1][1];
            dp[i][1] = (1ll * ((vec[i] - 1 - vec[i - 1]) / 2) * dp[i][0]) % mod;
            if (vec[i - 1] % 2 == vec[i] % 2) {
                dp[i][1] += dp[i - 1][1];
                dp[i][1] %= mod;
            }
        }
        cout << (dp[sz - 1][0] + dp[sz - 1][1]) % mod << endl;
    }
}

Compilation message

fib.cpp: In function 'std::vector<int> Delete(std::vector<int>, int)':
fib.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
fib.cpp: In function 'int main()':
fib.cpp:37:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             for (int i = 1; i < vec.size(); i++) {
      |                             ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Execution timed out 4018 ms 1364 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -