Submission #134465

#TimeUsernameProblemLanguageResultExecution timeMemory
134465dragonslayeritFibonacci representations (CEOI18_fib)C++14
50 / 100
4030 ms1828 KiB
#include <cstdio> #include <set> #include <array> const int MOD=1e9+7; std::set<int> zk; void increment(int A){ if(A==-1) return; if(A==0) A=1; if(zk.count(A+1)){ zk.erase(A+1); increment(A+2); }else if(zk.count(A-1)){ zk.erase(A-1); increment(A+1); }else if(zk.count(A)){ zk.erase(A); increment(A-2); increment(A+1); }else{ zk.insert(A); } } int main(){ int N; scanf("%d",&N); for(int i=0;i<N;i++){ int A; scanf("%d",&A); increment(A); int prev=0; std::array<int,2> dp={0,1}; //dp[0]=number of ways where prev-1 is used but prev is not //dp[1]=number of ways where prev is used but prev+1 is not for(int x:zk){ dp={(((x-prev)/2)*1LL*dp[0]+((x-prev-1)/2)*1LL*dp[1])%MOD,(dp[0]+dp[1])%MOD}; prev=x; } printf("%d\n",(dp[0]+dp[1])%MOD); } }

Compilation message (stderr)

fib.cpp: In function 'int main()':
fib.cpp:39:60: warning: narrowing conversion of '((((((long long int)((x - prev) / 2)) * 1) * ((long long int)dp.std::array<int, 2>::operator[](0))) + ((((long long int)(((x - prev) - 1) / 2)) * 1) * ((long long int)dp.std::array<int, 2>::operator[](1)))) % 1000000007)' from 'long long int' to 'int' inside { } [-Wnarrowing]
       dp={(((x-prev)/2)*1LL*dp[0]+((x-prev-1)/2)*1LL*dp[1])%MOD,(dp[0]+dp[1])%MOD};
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
fib.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&N);
   ~~~~~^~~~~~~~~
fib.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&A);
     ~~~~~^~~~~~~~~
#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...