CSES - Putka Open 2015 – 5/6 - Results
Submission details
Task:Käännöt
Sender:
Submission time:2015-11-08 05:48:25 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:29:65: error: expected ')' before ';' token
     sum+=(s[k]-'0')*((pow10[k]*(pairs(k+1)+pairs(n-k))+T[k])%MOD;
                                                                 ^

Code

#include <stdint.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

const uint64_t MOD=1000*1000*1000+7;

uint64_t pairs(uint64_t a){return a?((a-1)*(a-2)/2+a-1):0;}

int main(){
  std::string s;std::cin>>s;
  std::reverse(s.begin(),s.end());
  uint64_t n = s.size();

  std::vector<uint64_t>pow10(n);pow10[0]=1;
  for(unsigned i=1;i<n;++i)pow10[i]=(pow10[i-1]*10)%MOD;

  auto pow10_range=pow10;
  for(unsigned i=1;i<n;++i)(pow10_range[i]+=pow10_range[i-1])%=MOD;

  std::vector<uint64_t>T(n);
  T[n-1]=T[0]=pow10_range[n-1];
  for(unsigned i=1;i<(n+1)/2;++i)
    T[n-i-1]=T[i]=(T[i-1]+pow10_range[n-i-1]-pow10_range[i-1]+MOD)%MOD;

  uint64_t sum=0;
  for(unsigned k=0;k<n;++k){
    sum+=(s[k]-'0')*((pow10[k]*(pairs(k+1)+pairs(n-k))+T[k])%MOD;
    sum%=MOD;
  }
  std::cout<<sum<<'\n';
}