QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691575 | #7658. German Conference for Public Counting | duong2803 | AC ✓ | 1ms | 3844kb | C++14 | 4.7kb | 2024-10-31 12:05:02 | 2024-10-31 12:05:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s)
{
return '"' + s + '"';
}
string to_string(const char* s)
{
return to_string((string)s);
}
string to_string(bool b)
{
return (b ? "true" : "false");
}
string to_string(vector<bool> v)
{
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v)
{
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v)
{
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p)
{
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// #define int long long
int dp[11][11][2];
int dpz[11][11][2][2];
int cal(const vector<int>& digit, int d)
{
int n = digit.size();
memset(dp, 0, sizeof(dp));
dp[0][0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int cnt = 0; cnt <= 10; ++cnt) {
for (int lower = 0; lower < 2; ++lower) {
if (dp[i][cnt][lower] == 0)
continue;
for (int ndigit = 0; ndigit <= 9; ++ndigit) {
if (ndigit > digit[i] && lower == 0)
continue;
int nlower = lower || ndigit < digit[i];
int ncnt = cnt + (ndigit == d);
dp[i + 1][ncnt][nlower] = 1;
}
}
}
}
int res = 0;
for (int i = 0; i <= 10; ++i)
if (dp[n][i][0] || dp[n][i][1])
res = max(res, i);
debug(d, res);
return res;
}
int calz(const vector<int>& digit)
{
int n = digit.size();
memset(dp, 0, sizeof(dp));
dpz[0][0][0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int cnt = 0; cnt <= 10; ++cnt) {
for (int lower = 0; lower < 2; ++lower) {
for (int zero = 0; zero < 2; ++zero) {
if (dpz[i][cnt][lower][zero] == 0)
continue;
for (int ndigit = 0; ndigit <= 9; ++ndigit) {
if (ndigit > digit[i] && lower == 0)
continue;
int nlower = lower || ndigit < digit[i];
int ncnt = cnt + (ndigit == 0 && zero == 1);
int nzero = zero || (ndigit != 0);
dpz[i + 1][ncnt][nlower][nzero] = 1;
}
}
}
}
}
int res = 1;
for (int i = 0; i <= 10; ++i)
if (dpz[n][i][0][1] || dpz[n][i][1][1])
res = max(res, i);
return res;
}
void solve()
{
int n;
cin >> n;
vector<int> digit;
while (n) {
digit.push_back(n % 10);
n /= 10;
}
reverse(digit.begin(), digit.end());
int res = 0;
for (int i = 1; i <= 9; ++i)
res += cal(digit, i);
res += calz(digit);
cout << res << '\n';
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("out.txt", "w", stdout);
freopen("in.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
5
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
20
output:
11
result:
ok single line: '11'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
44
output:
14
result:
ok single line: '14'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
271828182
output:
82
result:
ok single line: '82'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
314159265
output:
82
result:
ok single line: '82'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
2
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
4
output:
5
result:
ok single line: '5'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6
output:
7
result:
ok single line: '7'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
7
output:
8
result:
ok single line: '8'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
8
output:
9
result:
ok single line: '9'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
9
output:
10
result:
ok single line: '10'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
10
output:
10
result:
ok single line: '10'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
11
output:
11
result:
ok single line: '11'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
12
output:
11
result:
ok single line: '11'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
13
output:
11
result:
ok single line: '11'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
14
output:
11
result:
ok single line: '11'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
15
output:
11
result:
ok single line: '11'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
16
output:
11
result:
ok single line: '11'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
17
output:
11
result:
ok single line: '11'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
18
output:
11
result:
ok single line: '11'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
19
output:
11
result:
ok single line: '11'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
21
output:
11
result:
ok single line: '11'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
22
output:
12
result:
ok single line: '12'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
23
output:
12
result:
ok single line: '12'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
24
output:
12
result:
ok single line: '12'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
25
output:
12
result:
ok single line: '12'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
999999998
output:
88
result:
ok single line: '88'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
999999999
output:
89
result:
ok single line: '89'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1000000000
output:
90
result:
ok single line: '90'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
291304289
output:
82
result:
ok single line: '82'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
73449290
output:
76
result:
ok single line: '76'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
3158503
output:
62
result:
ok single line: '62'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
307868725
output:
82
result:
ok single line: '82'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
59620920
output:
75
result:
ok single line: '75'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
266509490
output:
82
result:
ok single line: '82'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
457691930
output:
84
result:
ok single line: '84'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
320759563
output:
82
result:
ok single line: '82'
Test #40:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
863610963
output:
87
result:
ok single line: '87'
Test #41:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
393478602
output:
83
result:
ok single line: '83'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
432051206
output:
83
result:
ok single line: '83'
Test #43:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
508538239
output:
84
result:
ok single line: '84'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
330284500
output:
82
result:
ok single line: '82'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
539687131
output:
84
result:
ok single line: '84'
Test #46:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
216019046
output:
81
result:
ok single line: '81'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
895505788
output:
88
result:
ok single line: '88'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
283704301
output:
82
result:
ok single line: '82'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
160177746
output:
81
result:
ok single line: '81'
Test #50:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
835665161
output:
87
result:
ok single line: '87'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
818890757
output:
87
result:
ok single line: '87'
Test #52:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
888888887
output:
87
result:
ok single line: '87'
Test #53:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
888888888
output:
88
result:
ok single line: '88'
Test #54:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
888888889
output:
88
result:
ok single line: '88'
Test #55:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
55555556
output:
75
result:
ok single line: '75'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
444444
output:
54
result:
ok single line: '54'
Test #57:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
999
output:
29
result:
ok single line: '29'
Test #58:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
100001
output:
50
result:
ok single line: '50'
Test #59:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
333333333
output:
83
result:
ok single line: '83'
Test #60:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
22222221
output:
71
result:
ok single line: '71'
Test #61:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
111111110
output:
80
result:
ok single line: '80'
Test #62:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
6666665
output:
65
result:
ok single line: '65'