제출 #283094

#제출 시각아이디문제언어결과실행 시간메모리
283094FashoPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
1 ms512 KiB
#include <bits/stdc++.h> #define N 20 #define ll long long int #define fo(i,x,y) for(int i=x;i<=y;i++) #define fs(ar,n) fo(i,1,n) cin>>ar[i] #define sp " " #define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false) #define pb push_back #define ppb pop_back #define fi first #define se second #define ii pair<int,int> #define lli pair<ll,ll> #define fast2 freopen ("in.txt","r",stdin);freopen ("out.txt","w",stdout); #define mod 1000000007 using namespace std; ll n,m,ar[N],sum,t,pw[30],dp[N][11][11][3][2]; char s[N],c[N]; ll f(int ind,int l1,int l2,int flag,int tut) { if(dp[ind][l1][l2][flag][tut]!=-1) return dp[ind][l1][l2][flag][tut]; if(ind>n) return min(flag,1); ll top=0; // tutmac=max(tutmac,2); if(!tut) { fo(i,0,ar[ind]) { ll x=tut; if(i!=ar[ind]) x=1; if(i!=l1 && i!=l2) top+=f(ind+1,l2,i,min(flag+1,2),x); if(i==0 && flag==1) top+=f(ind+1,l2,i,min(flag+1,2),x); } } else fo(i,0,9) { ll x=tut; if(i!=ar[ind]) x=1; if(i!=l1 && i!=l2) top+=f(ind+1,l2,i,min(flag+1,2),1); if(i==0 && flag==1 && l1==0 && l2!=0) top+=f(ind+1,l2,i,min(flag+1,2),1); } if(!flag) top+=f(ind+1,0,0,0,1); // cout<<ind<<sp<<l1<<sp<<l2<<sp<<top<<endl; return dp[ind][l1][l2][flag][tut]=top; } ll calc() { return f(1,0,0,0,0); } int main() { fast; cin>>c+1; cin>>s+1; memset(dp,-1,sizeof(dp)); pw[0]=1; fo(i,1,20) pw[i]=pw[i-1]*8; n=strlen(s+1); fo(i,1,n) ar[i]=s[i]-'0'; sum=calc(); // cout<<"[d]"<<sp; // cout<<sum<<endl; n=strlen(c+1); fo(i,1,n) ar[i]=c[i]-'0'; memset(dp,-1,sizeof(dp)); ll y=calc(); sum-=y; // cout<<"[d]"<<sp; // cout<<y<<endl; ar[0]=10; ll flag=1; fo(i,2,n) if(ar[i]==ar[i-1] || ar[i]==ar[i-2]) flag=0; sum+=flag; cout<<sum<<endl; }

컴파일 시 표준 에러 (stderr) 메시지

numbers.cpp: In function 'long long int f(int, int, int, int, int)':
numbers.cpp:47:7: warning: variable 'x' set but not used [-Wunused-but-set-variable]
   47 |    ll x=tut;
      |       ^
numbers.cpp: In function 'int main()':
numbers.cpp:70:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |  cin>>c+1;
      |       ~^~
numbers.cpp:71:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |  cin>>s+1;
      |       ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...