Submission #61378456
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream> // 基本输入输出流
#include <algorithm> // 通用算法(排序、查找、去重、二分查找等)
#include <vector> // 动态数组(空间不够会自动扩容)
#include <queue> // 队列(先进先出)
#include <stack> // 栈(先进后出)
#include <set> // 集合(有序不重复)
#include <map> // 键值对容器(映射)
#include <list> // 双向链表
#include <math.h> // 数学函数
#include <functional> // 通用的函数绑定和调用机制
#include <cstring>
#define endl '\n'
#define pii pair<int, int>
#define pdd pair<double, double>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define int long long
using namespace std;
const int inf = 1e9 + 7;
const int mod = 998244353;
const int N = 2e5 + 10, M = N << 1;
int dp[20][10];
int dfs(const string &num, int pos, int pmax, bool ilm, bool ium) {
if (pos == num.size()) return ium;
if (!ilm && ium && dp[pos][pmax] != -1)
return dp[pos][pmax];
int res = 0;
if (!ium)
res = dfs(num, pos + 1, 0, false, false);
int sat = ium ? 0 : 1;
int end = ilm ? num[pos] - '0' : 9;
for (int i = sat; i <= end; ++i) {
if (!ium || i < pmax)
res += dfs(num, pos + 1, max(pmax, i), ilm && i == end, true);
}
if (!ilm && ium)
dp[pos][pmax] = res;
return res;
}
int solveQ(int x) {
if (x < 10) return 0;
string s = to_string(x);
memset(dp, -1, sizeof(dp));
return dfs(s, 0, 0, true, false);
}
void solve(){
int l, r;
cin >> l >> r;
cout << solveQ(r) - solveQ(l - 1) << endl;
}
signed main(){
//重定向输入输出
// freopen("pow.in", "r", stdin);
// freopen("pow.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int _ = 1;
// cin >> _; // 非多组测试数据请注释该行
while(_--) solve();
return 0;
}
Submission Info
Submission Time
2025-01-04 12:14:21
Task
C - Snake Numbers
User
Digital_Enigma
Language
C++ 20 (gcc 12.2)
Score
0
Code Size
1998 Byte
Status
WA
Exec Time
1 ms
Memory
3608 KB
Compile Error
Main.cpp: In function ‘long long int dfs(const std::string&, long long int, long long int, bool, bool)’:
Main.cpp:28:13: 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]
28 | if (pos == num.size()) return ium;
| ~~~~^~~~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 350
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
1 ms
3476 KB
00_sample_01.txt
AC
1 ms
3552 KB
00_sample_02.txt
AC
1 ms
3536 KB
01_random_00.txt
AC
1 ms
3484 KB
01_random_01.txt
AC
1 ms
3476 KB
01_random_02.txt
AC
1 ms
3604 KB
01_random_03.txt
AC
1 ms
3472 KB
01_random_04.txt
AC
1 ms
3424 KB
01_random_05.txt
AC
1 ms
3604 KB
01_random_06.txt
AC
1 ms
3440 KB
01_random_07.txt
AC
1 ms
3404 KB
01_random_08.txt
AC
1 ms
3476 KB
01_random_09.txt
AC
1 ms
3412 KB
02_random2_00.txt
AC
1 ms
3472 KB
02_random2_01.txt
AC
1 ms
3424 KB
02_random2_02.txt
AC
1 ms
3420 KB
02_random2_03.txt
AC
1 ms
3476 KB
03_random3_00.txt
AC
1 ms
3476 KB
03_random3_01.txt
AC
1 ms
3416 KB
03_random3_02.txt
AC
1 ms
3484 KB
03_random3_03.txt
AC
1 ms
3608 KB
03_random3_04.txt
AC
1 ms
3468 KB
04_handmade_00.txt
WA
1 ms
3480 KB
04_handmade_01.txt
AC
1 ms
3412 KB
04_handmade_02.txt
WA
1 ms
3552 KB
04_handmade_03.txt
WA
1 ms
3556 KB
04_handmade_04.txt
WA
1 ms
3412 KB
04_handmade_05.txt
WA
1 ms
3604 KB
04_handmade_06.txt
WA
1 ms
3404 KB