이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll fir, sec;
cin>>fir>>sec;
fir--;
string a=to_string(fir);
string b=to_string(sec);
ll ans1=0, ans2=0;
if(fir!=-1){
vector<vector<vector<array<ll, 2> > > >dp(19, vector<vector<array<ll, 2> > >(10, vector<array<ll, 2> >(10)));
// 0 -> limit, 1 -> no limit
// dig_pos, dig_val, dig_after_val
for(int i=a.size()-1;i>=0;i--){
if(i==a.size()-1){
for(int j=0;j<10;j++){
dp[i][j][0][j<=a[i]-'0']++;
}
for(int j1=0;j1<10;j1++){
for(int j2=0;j2<10;j2++){
ans1+=dp[i][j1][j2][1]+(i==0?0:dp[i][j1][j2][0]);
}
}
}
else if(i==a.size()-2){
for(int j=0;j<10;j++){
for(int j1=0;j1<10;j1++){
if(j==j1)
continue;
if(j>a[i]-'0')
dp[i][j][j1][0]+=dp[i+1][j1][0][0]+dp[i+1][j1][0][1];
else if(j<a[i]-'0')
dp[i][j][j1][1]+=dp[i+1][j1][0][0]+dp[i+1][j1][0][1];
else
dp[i][j][j1][1]+=dp[i+1][j1][0][1], dp[i][j][j1][0]+=dp[i+1][j1][0][0];
}
}
for(int j1=1;j1<10;j1++){
for(int j2=0;j2<10;j2++){
ans1+=dp[i][j1][j2][1]+(i==0?0:dp[i][j1][j2][0]);
}
}
}
else{
for(int j=0;j<10;j++){
for(int j1=0;j1<10;j1++){
for(int j2=0;j2<10;j2++){
if(j1==j || j2==j)
continue;
if(j>a[i]-'0')
dp[i][j][j1][0]+=dp[i+1][j1][j2][0]+dp[i+1][j1][j2][1];
else if(j<a[i]-'0')
dp[i][j][j1][1]+=dp[i+1][j1][j2][0]+dp[i+1][j1][j2][1];
else
dp[i][j][j1][1]+=dp[i+1][j1][j2][1], dp[i][j][j1][0]+=dp[i+1][j1][j2][0];
}
}
}
for(int j1=1;j1<10;j1++){
for(int j2=0;j2<10;j2++){
ans1+=dp[i][j1][j2][1]+(i==0?0:dp[i][j1][j2][0]);
}
}
}
}
}
a=b;
{
vector<vector<vector<array<ll, 2> > > >dp(19, vector<vector<array<ll, 2> > >(10, vector<array<ll, 2> >(10)));
// 0 -> limit, 1 -> no limit
// dig_pos, dig_val, dig_after_val
for(int i=a.size()-1;i>=0;i--){
if(i==a.size()-1){
for(int j=0;j<10;j++){
dp[i][j][0][j<=a[i]-'0']++;
}
for(int j1=0;j1<10;j1++){
for(int j2=0;j2<10;j2++){
ans2+=dp[i][j1][j2][1]+(i==0?0:dp[i][j1][j2][0]);
}
}
}
else if(i==a.size()-2){
for(int j=0;j<10;j++){
for(int j1=0;j1<10;j1++){
if(j==j1)
continue;
if(j>a[i]-'0')
dp[i][j][j1][0]+=dp[i+1][j1][0][0]+dp[i+1][j1][0][1];
else if(j<a[i]-'0')
dp[i][j][j1][1]+=dp[i+1][j1][0][0]+dp[i+1][j1][0][1];
else
dp[i][j][j1][1]+=dp[i+1][j1][0][1], dp[i][j][j1][0]+=dp[i+1][j1][0][0];
}
}
for(int j1=1;j1<10;j1++){
for(int j2=0;j2<10;j2++){
ans2+=dp[i][j1][j2][1]+(i==0?0:dp[i][j1][j2][0]);
}
}
}
else{
for(int j=0;j<10;j++){
for(int j1=0;j1<10;j1++){
for(int j2=0;j2<10;j2++){
if(j1==j || j2==j)
continue;
if(j>a[i]-'0')
dp[i][j][j1][0]+=dp[i+1][j1][j2][0]+dp[i+1][j1][j2][1];
else if(j<a[i]-'0')
dp[i][j][j1][1]+=dp[i+1][j1][j2][0]+dp[i+1][j1][j2][1];
else
dp[i][j][j1][1]+=dp[i+1][j1][j2][1], dp[i][j][j1][0]+=dp[i+1][j1][j2][0];
}
}
}
for(int j1=1;j1<10;j1++){
for(int j2=0;j2<10;j2++){
ans2+=dp[i][j1][j2][1]+(i==0?0:dp[i][j1][j2][0]);
}
}
}
}
}
cout<<ans2-ans1;
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In function 'int main()':
numbers.cpp:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(i==a.size()-1){
| ~^~~~~~~~~~~~
numbers.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | else if(i==a.size()-2){
| ~^~~~~~~~~~~~
numbers.cpp:81:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | if(i==a.size()-1){
| ~^~~~~~~~~~~~
numbers.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | else if(i==a.size()-2){
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |