Submission #8581573
Source Code Expand
Copy
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;
template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
int main() {
int n; scanf("%d", &n);
std::vector<int> d(n);
std::vector<i64> c(n);
for(int i = 0; i < n; i++) scanf("%d%lld", &d[i], &c[i]);
// solve
std::vector<i64> T(10, 0), S(10, 0);
for(int D = 1; D < 10; D++) {
int now = D;
while(true) {
if(now > 9) now = now % 10 + now / 10;
else {
now = now + D;
T[D]++;
}
S[D]++;
if(now == D) break;
}
}
//~ for(auto v: T) cout << v << " "; cout << endl;
//~ for(auto v: S) cout << v << " "; cout << endl;
i64 ans = -1, now = 0;
for(int i = 0; i < n; i++) {
if(d[i] == 0) {
ans += c[i];
} else if(d[i] == 9) {
ans += (c[i] - 1) * 2LL;
int tan = 1;
while(tan) {
if(now > 9) now = now % 10 + now / 10;
else {
now = now + d[i];
tan--;
}
ans++;
}
} else {
int tan = 0;
if(c[i] % T[d[i]]) {
ans += c[i] / T[d[i]] * S[d[i]];
tan = c[i] % T[d[i]];
} else {
ans += (c[i] / T[d[i]] - 1) * S[d[i]];
tan = T[d[i]];
}
while(tan) {
if(now > 9) now = now % 10 + now / 10;
else {
now = now + d[i];
tan--;
}
ans++;
}
}
// cout << i << ": " << ans << " " << now << endl;
}
if(now > 9) ans++;
printf("%lld\n", ans);
return 0;
}
Submission Info
Submission Time
2019-11-23 21:55:59+0900
Task
D - Digit Sum Replace
User
ecasdqina
Language
C++14 (GCC 5.4.1)
Score
500
Code Size
1701 Byte
Status
AC
Exec Time
46 ms
Memory
2560 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:21:57: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 3 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long int> >::value_type* {aka long int*}’ [-Wformat=]
for(int i = 0; i < n; i++) scanf("%d%lld", &d[i], &c[i]);
^
./Main.cpp:84:22: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘i64 {aka long int}’ [-Wformat=]
printf("%lld\n", ans);
^
./Main.cpp:18:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int n; scanf("%d", &n);
^
./Main.cpp:21:58: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(int i = 0; i < n; i++) scanf("%d%lld", &d[i], &c[i]);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
Set Name
Test Cases
Sample
00-sample-01.txt, 00-sample-02.txt
All
00-sample-01.txt, 00-sample-02.txt, 01-corner-01.txt, 01-corner-02.txt, 01-corner-03.txt, 02-random-01.txt, 02-random-02.txt, 02-random-03.txt, 02-random-04.txt, 02-random-05.txt, 02-random-06.txt, 02-random-07.txt, 02-random-08.txt, 02-random-09.txt, 02-random-10.txt, 02-random-11.txt, 03-max-01.txt, 03-max-02.txt, 04-min-01.txt, 04-min-02.txt
Case Name
Status
Exec Time
Memory
00-sample-01.txt
AC
1 ms
256 KB
00-sample-02.txt
AC
1 ms
256 KB
01-corner-01.txt
AC
1 ms
256 KB
01-corner-02.txt
AC
1 ms
256 KB
01-corner-03.txt
AC
1 ms
256 KB
02-random-01.txt
AC
1 ms
256 KB
02-random-02.txt
AC
1 ms
256 KB
02-random-03.txt
AC
1 ms
256 KB
02-random-04.txt
AC
1 ms
256 KB
02-random-05.txt
AC
1 ms
256 KB
02-random-06.txt
AC
45 ms
2560 KB
02-random-07.txt
AC
45 ms
2560 KB
02-random-08.txt
AC
45 ms
2560 KB
02-random-09.txt
AC
44 ms
2432 KB
02-random-10.txt
AC
46 ms
2560 KB
02-random-11.txt
AC
46 ms
2560 KB
03-max-01.txt
AC
31 ms
1920 KB
03-max-02.txt
AC
1 ms
256 KB
04-min-01.txt
AC
32 ms
2048 KB
04-min-02.txt
AC
1 ms
256 KB