Submission #283092

# Submission time Handle Problem Language Result Execution time Memory
283092 2020-08-25T09:56:06 Z Fasho Palindrome-Free Numbers (BOI13_numbers) C++14
51.6667 / 100
2 ms 416 KB
#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;
	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;


} 

Compilation message

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;
      |       ~^~
numbers.cpp:91:5: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
   91 |  ll flag=1;
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 1 ms 384 KB Output isn't correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Incorrect 1 ms 384 KB Output isn't correct
11 Correct 1 ms 384 KB Output is correct
12 Incorrect 1 ms 384 KB Output isn't correct
13 Correct 1 ms 384 KB Output is correct
14 Incorrect 1 ms 384 KB Output isn't correct
15 Incorrect 1 ms 384 KB Output isn't correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct
19 Incorrect 1 ms 384 KB Output isn't correct
20 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Incorrect 1 ms 384 KB Output isn't correct
11 Incorrect 1 ms 384 KB Output isn't correct
12 Incorrect 1 ms 416 KB Output isn't correct
13 Incorrect 1 ms 384 KB Output isn't correct
14 Incorrect 1 ms 384 KB Output isn't correct
15 Correct 1 ms 384 KB Output is correct
16 Incorrect 1 ms 384 KB Output isn't correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Incorrect 1 ms 384 KB Output isn't correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Incorrect 2 ms 384 KB Output isn't correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Incorrect 2 ms 384 KB Output isn't correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Incorrect 1 ms 384 KB Output isn't correct
36 Incorrect 1 ms 384 KB Output isn't correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Incorrect 1 ms 384 KB Output isn't correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct