제출 #166707

#제출 시각아이디문제언어결과실행 시간메모리
166707David_MPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
4 ms836 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std; 
ll a[30],d[30][30][30][2],l,r,i,j,k,t,n,U;
ll A(ll x){
	memset(d,0,sizeof(d));U=0;
    string s=to_string(x);n=s.size();
	for(i=1;i<=n;i++)a[i]=s[i-1]-'0';
	for(j=1;j<=a[1];j++)for(k=0;k<=9;k++)
    		d[2][j][k][0]=(j!=k)*(j<a[1]||k<a[2]),
    		d[2][j][k][1]=(j!=k)*(j==a[1])*(k==a[2]);
    for(i=2;i<n;i++)for(j=0;j<=9;j++)for(k=0;k<=9;k++)for(t=0;t<=9;t++)
    	d[i+1][k][t][0]+=(d[i][j][k][0]+d[i][j][k][1]*(t<a[i+1])*(k==a[i]))*(t!=k)*(t!=j)*(k!=j),
    	d[i+1][k][t][1]+=d[i][j][k][1]*(k==a[i])*(t==a[i+1])*(t!=k)*(t!=j)*(k!=j);

    for(j=0;j<=9;j++)for(k=0;k<=9;k++)U+=d[n][j][k][0]+d[n][j][k][1]; 
    for(i=0;i<n-2;i++)U+=81<<(3*i);
	if(n<2)return x+1; return U+10;
}
main(){cin>>l>>r; cout<<A(r)-min(2*l,A(l-1));}

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

numbers.cpp: In function 'long long int A(long long int)':
numbers.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if(n<2)return x+1; return U+10;
  ^~
numbers.cpp:18:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if(n<2)return x+1; return U+10;
                     ^~~~~~
numbers.cpp: At global scope:
numbers.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){cin>>l>>r; cout<<A(r)-min(2*l,A(l-1));}
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...