提交时间:2026-04-19 17:05:51

运行 ID: 318123

#pragma GCC optimize("O2") #include<bits/stdc++.h> #define endl '\n' #define ls i<<1 #define rs (i<<1|1) #define fi first #define se second #define pb push_back #define eb emplace_back #define bug cout<<"I AM HERE"<<endl using namespace std; using ll=long long; template<typename U,typename V>bool cmin(U &x,const V&y){return y<x?x=y,true:false;}; template<typename U,typename V>bool cmax(U &x,const V&y){return y>x?x=y,true:false;}; #define to(i,o,p) for(ll i=o;i<=p;++i) #define un(i,o,p) for(ll i=o;i>=p;--i) double round(double x){return ll(x+0.5);} using ull=unsigned long long; using LL=__int128; using ld=long double; using pii=pair<int,int>; using pll=pair<ll,ll>; const ll INF=0x3f3f3f3f3f3f3f3f; const int INT_INF=0x3f3f3f3f; const int int_inf=1E9+7; const double eps=1E-8; const ll inf=1E18+7; const int P=0; const int mod=1E9+7; const int M=2E5+10; const int N=2E5+10; int n,cnt; queue<ll>p; void bfs(){ to(i,1,9){ if(i==n){ cout<<i<<endl; exit(0); } p.push(i); } cnt=0; while(!p.empty()){ ++cnt; ll num=p.front(); p.pop(); // cout<<cnt<<": "<<num<<endl; if(cnt==n){ cout<<num<<endl; exit(0); } int las=num%10; if(las==0){ p.push(num*10+0); p.push(num*10+1); }else if(las==9){ p.push(num*10+8); p.push(num*10+9); }else{ p.push(num*10+las-1); p.push(num*10+las); p.push(num*10+las+1); } } } int main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>n; bfs(); return 0; }