ソースコード 拡げる

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 {
ans += c[i] / T[d[i]] * S[d[i]];
int tan = c[i] % T[d[i]];

if(tan == 0) {
ans--;
}

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;
}

#### 提出情報

提出日時 2019-11-23 21:53:29+0900 D - Digit Sum Replace ecasdqina C++14 (GCC 5.4.1) 0 1617 Byte WA 45 ms 2560 KB

#### コンパイルエラー

./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:82: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]);
^

#### ジャッジ結果

セット名 Sample All

 AC × 2
 AC × 10 WA × 10
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
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 WA 1 ms 256 KB
02-random-03.txt WA 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 WA 44 ms 2560 KB
02-random-07.txt WA 45 ms 2560 KB
02-random-08.txt WA 45 ms 2560 KB
02-random-09.txt WA 43 ms 2432 KB
02-random-10.txt WA 45 ms 2560 KB
02-random-11.txt WA 45 ms 2560 KB
03-max-01.txt WA 31 ms 1920 KB
03-max-02.txt AC 1 ms 256 KB
04-min-01.txt WA 32 ms 2048 KB
04-min-02.txt AC 1 ms 256 KB