# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1082823 | lamlamlam | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int a,b,dp[20][2][11][11],n;
string s;
int f(int pos,int tight,int prev1,int prev2)
{
if(pos==n) return 1;
if(dp[pos][tight][prev1][prev2]!=-1) return dp[pos][tight][prev1][prev2];
int res = 0, ub = 9;
if(tight) ub = s[pos] - '0';
for(int i=0; i<=ub; i++){
if(i==prev1 or i==prev2) continue;
int is_tight = (tight && i==ub);
res += f(pos+1,is_tight,i,prev1);
}
return dp[pos][tight][prev1][prev2] = res;
}
int sol(int x)
{
for(int i=0; i<20; i++) for(int j=0; j<11; j++) for(int k=0; k<11; k++) dp[i][0][j][k] = dp[i][1][j][k] = -1;
s = to_string(x);
n = s.size();
return f(0,1,10,10);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#define task "troll"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> a >> b;
cout << sol(b) - sol(a-1);
cerr << "\nTime: " << clock();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |