| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 488809 | dpw4112001 | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1097 ms | 720 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int dp[18][11][11][2];
int solve(string s,int i,int last,int secondlast,int tight)
{
if(i == s.length())
{
return 1;
}
if(dp[i][last][secondlast][tight]!= -1)return dp[i][last][secondlast][tight];
int limit = tight ? s[i] - '0' : 9;
int ans = 0;
for(int d = 0;d<=limit;d++)
{
if(d == last)
continue;
if(d == secondlast)
continue;
ans = ans + solve(s,i+1,d,last,tight && (d == limit));
}
return dp[i][last][secondlast][tight] = ans;
}
int getAns(string s)
{
int ans = 1;
int l = s[0] - '0';
for(int i=1;i<=l;i++)
{
ans = ans + solve(s,1,i,i,i == l);
}
for(int i=2;i<s.size();i++)
{
for(int j=1;j<=9;j++)
{
ans += solve(s,i,j,j,0);
}
}
return ans;
}
signed main()
{
int t;
cin >> t;
while(t--)
{
int l,r;
cin >> l >> r;
memset(dp,-1,sizeof dp);
int x = getAns(to_string(l-1));
memset(dp,-1,sizeof dp);
int y = getAns(to_string(r));
// cout << x << ' ' << y << '\n';
cout << y - x << '\n';
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
