CSES - Putka Open 2015 – 3/6 - Results
Submission details
Task:Onnenluku
Sender:
Submission time:2015-09-11 22:04:26 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED19
#2ACCEPTED33
#3ACCEPTED48
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.05 s1details
#3ACCEPTED0.04 s1details
#4ACCEPTED0.05 s1details
#5ACCEPTED0.05 s1details
#6ACCEPTED0.05 s2details
#7ACCEPTED0.06 s2details
#8ACCEPTED0.06 s2details
#9ACCEPTED0.05 s2details
#10ACCEPTED0.05 s2details
#11ACCEPTED0.06 s3details
#12ACCEPTED0.06 s3details
#13ACCEPTED0.06 s3details
#14ACCEPTED0.05 s3details
#15ACCEPTED0.05 s3details

Compiler report

input/code.cpp: In function 'uint64_t upto(char, char, std::string)':
input/code.cpp:10:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1;i<str.size();++i)sum+=(1ULL<<i)-2;
                ^
input/code.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1;i<=str.size();++i){
                ^
input/code.cpp: In function 'std::string next(char, char, std::string)':
input/code.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<str.size();++i){
                ^
input/code.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<str.size();++i){
                ^
input/code.cpp:32:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(;i<str.size();++i)str[i]=x;
             ^
input/code.cpp:37:16: warning: compari...

Code

#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <string>

static const std::string DDDD("123456789");

std::uint64_t upto(char x,char y,std::string str){
  std::uint64_t sum=0;
  for(int i=1;i<str.size();++i)sum+=(1ULL<<i)-2;
  for(int i=1;i<=str.size();++i){
    if(str[str.size()-i]==y){
      sum+=(1ULL<<(i-1))-1;
      for(int j=str.size()-i;j>=0;--j){
        if(str[j]==y){
          ++sum;
          break;
        }
      }
    }
  }
  return sum;
}

std::string next(char x,char y,std::string str){
  for(int i=0;i<str.size();++i){
    if(str[i]<y)break;
    if(str[i]>y)return std::string(str.size()+1,x);
  }
  for(int i=0;i<str.size();++i){
    if(str[i]<x){
      for(;i<str.size();++i)str[i]=x;
      return str;
    }
    if(str[i]>x&&str[i]<y){
      str[i]=y;
      for(++i;i<str.size();++i)str[i]=x;
      return str;
    }
    if(str[i]>y)
      for(int j=i-1;j>=0;--j)
        if(str[j]==x){
          str[j]=y;
          for(++j;j<str.size();++j)str[j]=x;
          return str;
        }
  }
  return str;
}

std::string prev(char x,char y,std::string str){
  for(int i=0;i<str.size();++i){
    if(str[i]>x)break;
    if(str[i]<x)return std::string(str.size()-1,y);
  }
  for(int i=0;i<str.size();++i){
    if(str[i]>y){
      for(;i<str.size();++i)str[i]=y;
      return str;
    }
    if(str[i]>x&&str[i]<y){
      str[i]=x;
      for(++i;i<str.size();++i)str[i]=y;
      return str;
    }
    if(str[i]<x)
      for(int j=i-1;j>=0;--j)
        if(str[j]==y){
          str[j]=x;
          for(++j;j<str.size();++j)str[j]=y;
          return str;
        }
  }
  return str;
}

std::string prev2(char x,char y,std::string str){
  str=prev(x,y,str);
  if(str==std::string(str.size(),x))str=std::string(str.size()-1,y);
  if(str.size()<2)return std::string();
  if(str==std::string(str.size(),y))str[str.size()-1]=x;
  return str;
}

std::string next2(char x,char y,std::string str){
  str=next(x,y,str);
  if(str==std::string(str.size(),y))str=std::string(str.size()+1,x);
  if(str.size()<2)return std::string();
  if(str==std::string(str.size(),x))str[str.size()-1]=y;
  return str;
}

int main(){
  std::string a,b;std::cin>>a>>b;
  std::uint64_t n_n=0;
  for(char xd :DDDD)
    for(char xD :DDDD){
      if(xd>=xD)continue;
      auto A=next2(xd,xD,a);
      auto B=prev2(xd,xD,b);
      if(B.empty()||A.size()>B.size()||(A.size()==B.size()&&A>B))continue;
      std::uint64_t news=upto(xd,xD,B)-upto(xd,xD,A);
      if(!A.empty())++news;
      n_n+=news;
    }
  std::cout<<n_n<<'\n';
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
2157 93337

correct output
1421

user output
1421

Test 2

Group: 1

Verdict: ACCEPTED

input
4875 95124

correct output
1278

user output
1278

Test 3

Group: 1

Verdict: ACCEPTED

input
5577 96352

correct output
1245

user output
1245

Test 4

Group: 1

Verdict: ACCEPTED

input
8362 92950

correct output
1076

user output
1076

Test 5

Group: 1

Verdict: ACCEPTED

input
5658 96660

correct output
1238

user output
1238

Test 6

Group: 2

Verdict: ACCEPTED

input
51312303535233 994542403556353

correct output
1453976

user output
1453976

Test 7

Group: 2

Verdict: ACCEPTED

input
25636920452341 934558290712847

correct output
1544072

user output
1544072

Test 8

Group: 2

Verdict: ACCEPTED

input
7917952071965 985207415843573

correct output
1763176

user output
1763176

Test 9

Group: 2

Verdict: ACCEPTED

input
48991581181227 907034837225965

correct output
1380248

user output
1380248

Test 10

Group: 2

Verdict: ACCEPTED

input
47968703305149 924246001328437

correct output
1396632

user output
1396632

Test 11

Group: 3

Verdict: ACCEPTED

input
292953755324413237753216241025...

correct output
53286731528535944

user output
53286731528535944

Test 12

Group: 3

Verdict: ACCEPTED

input
373990979330820426927419348165...

correct output
51580289482227600

user output
51580289482227600

Test 13

Group: 3

Verdict: ACCEPTED

input
701417326319476057561825658890...

correct output
42924933948374952

user output
42924933948374952

Test 14

Group: 3

Verdict: ACCEPTED

input
177202883511434557056457305647...

correct output
54500592365600640

user output
54500592365600640

Test 15

Group: 3

Verdict: ACCEPTED

input
977665117437419620152569155919...

correct output
38562071809359800

user output
38562071809359800