제출 #943154

#제출 시각아이디문제언어결과실행 시간메모리
943154vjudge1Fibonacci representations (CEOI18_fib)C++17
15 / 100
4072 ms2324 KiB
#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; 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; } }

컴파일 시 표준 에러 (stderr) 메시지

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++) {
      |                             ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...