Submission #535179

# Submission time Handle Problem Language Result Execution time Memory
535179 2022-03-09T15:13:55 Z Koful123 Palindrome-Free Numbers (BOI13_numbers) C++17
0 / 100
4 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int dp[20][12][12][2];

int f(string s,int indx,int x,int y,int ok){
	
	if(indx == s.size())
		return 1;

	int &cur = dp[indx][x][y][ok];
	if(cur != -1)
		return cur;

	int fi = (indx == 0),se;
	if(ok) se = 9;
	else se = s[indx]-'0';

	for(int i=fi;i<=se;i++){
		if(i == x || i == y) continue;
		cur += f(s,indx+1,y,i,(ok||i<s[indx]-'0'));
	}

	return cur+=1;
}

void solve(){			

	int a,b;
	cin >> a >> b;

	memset(dp,-1,sizeof(dp));
	string tmp = to_string(a-1);
	int res = f(tmp,0,10,10,0);

	for(int i=2;i<tmp.size();i++){
		res += 81*pow(8,i-2);
	}

	memset(dp,-1,sizeof(dp));
	tmp = to_string(b);

	for(int i=2;i<tmp.size();i++){
		res -= 81*pow(8,i-2);
	}

	if(a > 9) res += 10;
	else if(a) res++; 
	if(b > 9) res -= 10;
	else res--;

	cout << f(tmp,0,10,10,0) - res << endl;
}

signed main(){

	ios_base::sync_with_stdio(0);	
	cin.tie(0);	

	#ifndef ONLINE_JUDGE
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
 
	int t = 1;
	//cin >> t;

 	for(int i=1;i<=t;i++){
 		solve();
	}

	return 0;
}

Compilation message

numbers.cpp: In function 'long long int f(std::string, long long int, long long int, long long int, long long int)':
numbers.cpp:16:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if(indx == s.size())
      |     ~~~~~^~~~~~~~~~~
numbers.cpp: In function 'void solve()':
numbers.cpp:44:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i=2;i<tmp.size();i++){
      |              ~^~~~~~~~~~~
numbers.cpp:51:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i=2;i<tmp.size();i++){
      |              ~^~~~~~~~~~~
numbers.cpp: In function 'int main()':
numbers.cpp:69:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |   freopen("in.txt","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~
numbers.cpp:70:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   freopen("out.txt","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Incorrect 2 ms 332 KB Output isn't correct
3 Incorrect 2 ms 332 KB Output isn't correct
4 Incorrect 2 ms 332 KB Output isn't correct
5 Incorrect 2 ms 332 KB Output isn't correct
6 Incorrect 4 ms 332 KB Output isn't correct
7 Incorrect 2 ms 332 KB Output isn't correct
8 Incorrect 2 ms 332 KB Output isn't correct
9 Incorrect 2 ms 332 KB Output isn't correct
10 Incorrect 2 ms 332 KB Output isn't correct
11 Incorrect 3 ms 332 KB Output isn't correct
12 Incorrect 4 ms 332 KB Output isn't correct
13 Incorrect 2 ms 332 KB Output isn't correct
14 Incorrect 2 ms 332 KB Output isn't correct
15 Incorrect 2 ms 332 KB Output isn't correct
16 Incorrect 2 ms 332 KB Output isn't correct
17 Incorrect 2 ms 332 KB Output isn't correct
18 Incorrect 2 ms 332 KB Output isn't correct
19 Incorrect 2 ms 332 KB Output isn't correct
20 Incorrect 2 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Incorrect 2 ms 332 KB Output isn't correct
3 Incorrect 2 ms 332 KB Output isn't correct
4 Incorrect 2 ms 332 KB Output isn't correct
5 Incorrect 2 ms 332 KB Output isn't correct
6 Incorrect 2 ms 332 KB Output isn't correct
7 Incorrect 2 ms 332 KB Output isn't correct
8 Incorrect 2 ms 332 KB Output isn't correct
9 Incorrect 2 ms 332 KB Output isn't correct
10 Incorrect 3 ms 332 KB Output isn't correct
11 Incorrect 2 ms 332 KB Output isn't correct
12 Incorrect 2 ms 332 KB Output isn't correct
13 Incorrect 2 ms 332 KB Output isn't correct
14 Incorrect 2 ms 332 KB Output isn't correct
15 Incorrect 2 ms 332 KB Output isn't correct
16 Incorrect 2 ms 332 KB Output isn't correct
17 Incorrect 2 ms 332 KB Output isn't correct
18 Incorrect 2 ms 332 KB Output isn't correct
19 Incorrect 2 ms 332 KB Output isn't correct
20 Incorrect 2 ms 332 KB Output isn't correct
21 Incorrect 2 ms 332 KB Output isn't correct
22 Incorrect 2 ms 332 KB Output isn't correct
23 Incorrect 2 ms 332 KB Output isn't correct
24 Incorrect 3 ms 332 KB Output isn't correct
25 Incorrect 2 ms 332 KB Output isn't correct
26 Incorrect 3 ms 332 KB Output isn't correct
27 Incorrect 2 ms 332 KB Output isn't correct
28 Incorrect 2 ms 332 KB Output isn't correct
29 Incorrect 2 ms 332 KB Output isn't correct
30 Incorrect 2 ms 332 KB Output isn't correct
31 Incorrect 2 ms 364 KB Output isn't correct
32 Incorrect 2 ms 332 KB Output isn't correct
33 Incorrect 2 ms 332 KB Output isn't correct
34 Incorrect 2 ms 332 KB Output isn't correct
35 Incorrect 2 ms 332 KB Output isn't correct
36 Incorrect 2 ms 332 KB Output isn't correct
37 Incorrect 2 ms 332 KB Output isn't correct
38 Incorrect 2 ms 332 KB Output isn't correct
39 Incorrect 2 ms 332 KB Output isn't correct
40 Incorrect 2 ms 332 KB Output isn't correct
41 Incorrect 2 ms 332 KB Output isn't correct
42 Incorrect 2 ms 332 KB Output isn't correct
43 Incorrect 2 ms 332 KB Output isn't correct
44 Incorrect 2 ms 332 KB Output isn't correct
45 Incorrect 2 ms 332 KB Output isn't correct