| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 166380 | achibasadzishvili | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 10 ms | 508 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll dp[25][12][12][3];
vector<ll>v;
ll solve(ll x){
if(x < 10)return x + 1;
ll xx = x;
v.clear();
while(x){
v.pb(x % 10);
x /= 10;
}
v.pb(-1);
reverse(v.begin() , v.end());
for(int i=0; i<=v.size(); i++)
for(int x=0; x<10; x++)
for(int y=0; y<=10; y++)
dp[i][x][y][0] = dp[i][x][y][1] = 0;
for(int x=1; x<10; x++)
for(int y=0; y<10; y++)
if(x != y || x == 0){
if(x < v[1] || (x == v[1] && y < v[2])){
dp[2][y][x][1] = 1;
}
if(x == v[1] && y == v[2])
dp[2][y][x][0] = 1;
}
for(int i=3; i<(int)v.size(); i++){
for(int n=0; n<10; n++)
for(int x=0; x<10; x++)
for(int y=0; y<10; y++){
if(x == y)continue;
if(n == x)continue;
if(n == y)continue;
dp[i][n][x][1] += dp[i - 1][x][y][1];
if(n < v[i])dp[i][n][x][1] += dp[i - 1][x][y][0];
if(n == v[i])dp[i][n][x][0] += dp[i - 1][x][y][0];
}
}
ll ret = 0;
ll n = (ll)v.size() - 1;
for(int x=0; x<10; x++)
for(int y=0; y<10; y++){
ret += dp[n][x][y][1] + dp[n][x][y][0];
}
return ret;
}
ll count(ll x){
ll ans = 0;
ans += solve(x);
ll raod = 0;
while(x){
raod++;
x /= 10;
}
ll p = 1;
for(int i=1; i<raod; i++){
p *= 10;
ans += solve(p - 1);
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
ll x,y;
cin >> x >> y;
cout << count(y) - count(x - 1) << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
