# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1029327 | kiethm07 | Palindrome-Free Numbers (BOI13_numbers) | C++11 | 1 ms | 460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int,int>
#define iii pair<int,pii>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pii>
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()
#define TEXT "a"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf = 1e9 + 7;
const ld eps = 1e-8;
const double pi = acos(-1);
ll dp[20][11][11][2][2];
string s;
int n;
string conv(ll x){
string res = "";
while(x){
res += (x % 10) + '0';
x /= 10;
}
reverse(all(res));
return res;
}
ll f(int pos,int l,int p,bool small,bool start){
if (pos == n) return 1;
ll &res = dp[pos][l][p][small][start];
if (res != -1) return res;
int num = s[pos] - '0';
res = 0;
for (int i = 0; i <= 9; i++){
bool nsmall = small | (i < num);
bool nstart = start | (i > 0);
if ((small == 0) && (i > num)) break;
if (start && (i == p || i == l)) continue;
res += f(pos + 1,i,l,nsmall,nstart);
}
return res;
}
ll cal(ll x){
if (x < 0) return 0;
memset(dp,-1,sizeof(dp));
s = conv(x);
n = s.size();
return f(0,10,10,0,0);
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
if (fopen(TEXT".inp","r")){
freopen(TEXT".inp","r",stdin);
freopen(TEXT".out","w",stdout);
}
ll a,b;
cin >> a >> b;
ll res = cal(b) - cal(a - 1);
cout << res << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |