이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int ll
using namespace std;
string str;
int dp[20][20][55][5][5];
int get(int last2 = 10,int last = 10,int pos = 0,int sm = 0,int p = 1){
if (pos >= str.size()) return dp[last2][last][pos][sm][p] = 1;
if (dp[last2][last][pos][sm][p] != -1)
return dp[last2][last][pos][sm][p];
int l = 9,sum=0;
if (!sm) l = str[pos] - '0';
for (int i=0;i<=l;i++){
if (i == last || i == last2) continue;
int sm2 = sm,p2 = p;
if (!sm2 && i < l) sm2 = 1;
if (i && p2) p2 = 0;
if (p2) sm2 = 1;
if (p2) sum += get(10,10,pos+1,sm2,p2);
else sum += get(last,i,pos + 1,sm2,p2);
}
return dp[last2][last][pos][sm][p] = sum;
}
int check(string a){
for (int i = 1; i < a.size(); i++){
if (a[i] == a[i - 1]) return 0;
if (i > 1 && a[i] == a[i - 2]) return 0;
}
return 1;
}
int G(int x){
if (x < 0) return 0;
memset(dp, -1, sizeof(dp));
str = "";
while(x){
str+=(x%10)+'0';
x/=10;
}
reverse(str.begin(),str.end());
return get();
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
ll a,b;
cin>>a>>b;
cout<<G(b) - G(a-1)<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
numbers.cpp:13:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if (pos >= str.size()) return dp[last2][last][pos][sm][p] = 1;
| ~~~~^~~~~~~~~~~~~
numbers.cpp: In function 'long long int check(std::string)':
numbers.cpp:32:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = 1; i < a.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |