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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:51:1: error: expected '}' at end of input
 }
 ^

Code

#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::ios_base::sync_with_stdio(false);
  std::string s;
  uint64_t n = 0;
  for (char c; std::cin >> c;) {
    if (c>='1'&&c<='9')s+=c,++n;
  std::reverse(s.begin(),s.end());

  if (n>3) throw n;
  for (char c:s) if (c < '1' || c > '9') throw c;

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

  uint64_t sum1=0;
  for(unsigned i=0;i<n;++i){
    for(unsigned j=i;j<n;++j){
      std::reverse(&s[i],&s[j+1]);
      for(unsigned k=0;k<n;++k)
	(sum1+=(s[k]-'0')*pow10[k])%=MOD;
      std::reverse(&s[i],&s[j+1]);
    }
  }

  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;

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