제출 #26378

#제출 시각아이디문제언어결과실행 시간메모리
26378samir_droubiPalindrome-Free Numbers (BOI13_numbers)C++14
13.75 / 100
0 ms2040 KiB
#include <bits/stdc++.h> using namespace std; long long a,b; long long dp[20][12][12]; long long calc(int i,int lst1,int lst2) { if(i==2)return lst1!=lst2; if(dp[i][lst1][lst2]!=-1)return dp[i][lst1][lst2]; long long ans=0; for(int j=0;j<=9;++j) { if(j!=lst1&&j!=lst2) ans=ans+calc(i-1,j,lst1); } return dp[i][lst1][lst2]=ans; } long long sm[20]; vector<int>v; long long f(long long x) { v.clear(); int y=x; while(x!=0) { v.push_back(x%10); x/=10; } if(v.size()==1) return y-1; if(v.size()==2) return y-1-(v[1]-1)-(v[0]-1>=v[1]); long long ans=0; for(int i=0;i<v.size();++i) { int lst1=10; int lst2=10; if(i<v.size()-1)lst1=v[i+1]; if(i<v.size()-2)lst2=v[i+2]; for(int j=(i==v.size()-1);j<v[i];++j) { if(j==lst2||j==lst1)continue; ans=ans+calc(i+2,j,lst1); } } return ans+sm[v.size()-1]; } int main() { memset(dp,-1,sizeof dp); scanf("%lld%lld",&a,&b); sm[1]=9; for(int i=2;i<=18;++i) { for(int j=1;j<=9;++j) for(int k=0;k<=9;++k) sm[i]+=calc(i,j,k); sm[i]+=sm[i-1]; } long long sa=f(a); long long sb=f(b+1); printf("%lld\n",sb-sa); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

numbers.cpp: In function 'long long int f(long long int)':
numbers.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();++i)
               ^
numbers.cpp:38:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i<v.size()-1)lst1=v[i+1];
       ^
numbers.cpp:39:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i<v.size()-2)lst2=v[i+2];
       ^
numbers.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=(i==v.size()-1);j<v[i];++j)
               ^
numbers.cpp: In function 'int main()':
numbers.cpp:51:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&a,&b);
                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...