Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Pablo Moreno Olalla
- Email address: darthbrevu@yahoo.es
- */
- #include <cstdio>
- #include <string>
- #include <numeric>
- #include <sstream>
- #include <iostream>
- using namespace std;
- unsigned long long initial=36; //Six zeros. From here, we add the delta for each second.
- unsigned long long transitions[]={0,4,1,1,2,1,1,4,0,1};
- unsigned long long transition50=2;
- unsigned long long transition30=2;
- unsigned long long transition20=2;
- unsigned long long accum10,accum6,accum4,accum2_;
- unsigned long long accumx[6];
- unsigned long long times[]={36000,3600,600,60,10};
- inline void initA() {
- accum10=accumulate(&transitions[0],&transitions[10],0);
- accum6=accumulate(&transitions[0],&transitions[5],transition50);
- accum4=accumulate(&transitions[0],&transitions[3],transition30);
- accum2_=transitions[0]+transitions[1]+transition20;
- accumx[0]=8786*accum10+1464*accum6+accum2_+accum4;
- accumx[1]=3661*accum10+610*accum6;
- accumx[2]=366*accum10+61*accum6;
- accumx[3]=61*accum10+10*accum6;
- accumx[4]=6*accum10+accum6;
- accumx[5]=accum10;
- }
- unsigned long long totalLeds(unsigned long long secs) {
- unsigned long long res=initial;
- unsigned long long d=secs/86400;
- secs%=86400;
- unsigned long q;
- res+=d*accumx[0];
- for (size_t i=0;i<5;++i) {
- q=secs/times[i];
- secs%=times[i];
- res+=accumulate(&transitions[0],&transitions[q],q*accumx[i+1]);
- }
- return accumulate(&transitions[0],&transitions[secs],res);
- }
- int main(int argc,char **argv) {
- //The first two lines are not strictly necessary, but make the code a little more handy.
- if (argc>=2) freopen(argv[1],"r",stdin);
- if (argc>=3) freopen(argv[2],"w",stdout);
- initA();
- string tmp;
- unsigned long long ull;
- do {
- getline(cin,tmp);
- istringstream iss(tmp);
- iss>>ull;
- if (!iss.fail()) cout<<totalLeds(ull)<<endl;
- } while (!cin.eof());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement