답안 #779944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779944 2023-07-12T03:41:09 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++17
42.5 / 100
1 ms 340 KB
//#pragma GCC optimize("conserve-stack,no-stack-protector")
#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
//#define int long long
//#define mod 998244353
using namespace std;
using ll=long long;
const int MN=1025;
int dp[20][11][11][2][2];
string t;
//const int inf = 1e18;
int DP(int pos, int lst1, int lst2, bool eq, bool start) {
	if(pos==t.size()) return 1;
	if(dp[pos][lst1+1][lst2+1][eq][start]!=-1) return dp[pos][lst1+1][lst2+1][eq][start];
	int ans=0;
	if(!start) {
		ans+=DP(pos+1,-1,-1,false,false);
		if(eq) {
			int limit=t[pos]-'0';
			for (int i=1; i<=limit; i++) {
				ans+=DP(pos+1,i,-1,(i==limit),true);
			}
		}
		else {
			for (int i=1; i<=9; i++) {
				ans+=DP(pos+1,i,-1,false,true);
			}
		}
	}
	else {
		if(eq) {
			int limit=t[pos]-'0';
			for (int i=0; i<=limit; i++) {
				if(i==lst1||i==lst2) continue;
				ans+=DP(pos+1,i,lst1,(i==limit), true);
			}
		}
		else {
			for (int i=0; i<=9; i++) {
				if(i==lst1||i==lst2) continue;
				ans+=DP(pos+1,i,lst1,false,true);
			}
		}
	}
	return dp[pos][lst1+1][lst2+1][eq][start]=ans;
}
int dp_digit(int x) {
	if(x<0) return 0;
	t=to_string(x);
	memset(dp,-1,sizeof(dp));
	return DP(0,-1,-1,1,0);
}
inline void solve() {
	int l,r;
	cin>>l>>r;
	cout<<dp_digit(r)-dp_digit(l-1);
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
	while(t--) {
		solve();
	}
}

Compilation message

numbers.cpp: In function 'int DP(int, int, int, bool, bool)':
numbers.cpp:18:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if(pos==t.size()) return 1;
      |     ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Incorrect 0 ms 340 KB Output isn't correct
20 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Incorrect 0 ms 340 KB Output isn't correct
17 Incorrect 0 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 0 ms 340 KB Output isn't correct
20 Incorrect 0 ms 340 KB Output isn't correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Incorrect 0 ms 340 KB Output isn't correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Incorrect 1 ms 340 KB Output isn't correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Incorrect 1 ms 340 KB Output isn't correct
27 Incorrect 0 ms 340 KB Output isn't correct
28 Incorrect 0 ms 340 KB Output isn't correct
29 Incorrect 0 ms 340 KB Output isn't correct
30 Incorrect 0 ms 340 KB Output isn't correct
31 Incorrect 0 ms 340 KB Output isn't correct
32 Incorrect 0 ms 340 KB Output isn't correct
33 Incorrect 0 ms 340 KB Output isn't correct
34 Incorrect 0 ms 340 KB Output isn't correct
35 Incorrect 1 ms 340 KB Output isn't correct
36 Incorrect 0 ms 340 KB Output isn't correct
37 Incorrect 0 ms 340 KB Output isn't correct
38 Incorrect 0 ms 340 KB Output isn't correct
39 Incorrect 0 ms 340 KB Output isn't correct
40 Incorrect 0 ms 340 KB Output isn't correct
41 Incorrect 0 ms 340 KB Output isn't correct
42 Incorrect 0 ms 340 KB Output isn't correct
43 Incorrect 0 ms 284 KB Output isn't correct
44 Incorrect 0 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct