Submission #00326


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 10;
long long factArray[MAX], invFactArray[MAX], invArray[MAX];
long long powMod(long long a, long long p) {
if (p == 0) {
return 1;
}
if (p % 2) {
return a * powMod(a, p - 1) % MOD;
} else {
long long t = powMod(a, p / 2);
return t * t % MOD;
}
}
long long fact(int n) {
if (factArray[n] != -1) {
return factArray[n];
}
return factArray[n] = n * fact(n - 1) % MOD;
}
using row = std::vector<long long>;
using matrix = std::vector<row>;
//(A * B) mod
matrix matrixMul(matrix &A, matrix &B, const int mod) {
const int asz = A.size();
const int bsz = B.size();
const int bcolsz = B.front().size();
matrix res(asz, row(bcolsz, 0));
for (int i = 0; i < asz; i++) {
for (int k = 0; k < bsz; k++) {
for (int j = 0; j < bcolsz; j++) {
(res[i][j] += A[i][k] * B[k][j]) %= mod;
}
}
}
return res;
}
//(mat^p) mod
matrix matPowMod(matrix &mat, long long p, const int mod) {
const int matsz = mat.size();
assert(mat.front().size() == matsz);//must square matrix!!
matrix res(matsz, row(matsz, 0));
for (int i = 0; i < matsz; i++) {
res[i][i] = 1;
}
while (p) {
if (p & 1) res = matrixMul(res, mat, mod);
mat = matrixMul(mat, mat, mod);
p >>= 1;
}
return res;
}
// ( matrix * vector ) % mod
row mul(matrix mat, row r, const int mod) {
assert(mat[0].size() == r.size());
row res(mat.size(), 0);
for (int i = 0; i < mat.size(); i++) {
for (int j = 0; j < r.size(); j++) {
(res[i] += mat[i][j] * r[j]) %= mod;
}
}
return res;
}
long long allCnt[10], cntCnt[10];
pair<long long, long long> mi = make_pair(MOD, 9);
long long calcMinNum() {
long long res = 0;
if (cntCnt[0]) {
allCnt[mi.first] -= mi.second;
vector<vector<long long>> mat(2, vector<long long>(2));
mat[0][0] = 10;
mat[0][1] = mi.first;
mat[1][0] = 0;
mat[1][1] = 1;
auto powMat = matPowMod(mat, mi.second - 1, MOD);
auto row = mul(powMat, vector<long long>{mi.first, 1}, MOD);
(res *= powMod(10, mi.second)) %= MOD;
(res += row[0]) %= MOD;
}
for (int i = 0; i < 10; i++) {
if (allCnt[i]) {
vector<vector<long long>> mat(2, vector<long long>(2));
mat[0][0] = 10;
mat[0][1] = i;
mat[1][0] = 0;
mat[1][1] = 1;
auto powMat = matPowMod(mat, allCnt[i] - 1, MOD);
auto row = mul(powMat, vector<long long>{i, 1}, MOD);
(res *= powMod(10, allCnt[i])) %= MOD;
(res += row[0]) %= MOD;
}
}
return res;
}
int main() {
memset(factArray, -1, sizeof(factArray));
factArray[0] = 1;
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
long long a, b;
scanf("%lld%lld", &a, &b);
allCnt[a] += b;
cntCnt[a]++;
if (a != 0) {
mi = min(mi, make_pair(a, b));
}
}
if (N == 1 && allCnt[0]) {
puts("0\n1");
return 0;
}
const long long miNum = calcMinNum();
if (allCnt[0]) {
cntCnt[mi.first]--;
}
long long comb = 1;
for (int i = 0; i < 10; i++) {
(comb *= fact(cntCnt[i])) %= MOD;
}
printf("%lld\n%lld\n", miNum, comb);
return 0;
}

ステータス

項目 データ
問題 0003 - repdigit
ユーザー名 sekiya9311
投稿日時 2017-07-07 22:46:17
言語 C++17
状態 Wrong Answer
得点 0
ソースコード長 3403 Byte
最大実行時間 1000 ms
最大メモリ使用量 2928 KB

セット

セット 得点 Cases
1 ALL 0 / 100 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01_sample1.in AC 16 ms 1244 KB
1
01_sample2.in AC 22 ms 1204 KB
1
01_sample3.in AC 12 ms 1292 KB
1
02_handmake1.in AC 12 ms 1252 KB
1
02_handmake2.in WA 16 ms 1208 KB
1
02_handmake3.in AC 12 ms 1292 KB
1
02_handmake4.in AC 15 ms 1252 KB
1
02_handmake5.in AC 12 ms 1212 KB
1
02_handmake6.in AC 12 ms 1296 KB
1
02_handmake7.in AC 12 ms 1248 KB
1
02_handmake8.in AC 12 ms 1208 KB
1
02_handmake9.in AC 20 ms 1296 KB
1
03_random1.in WA 12 ms 1384 KB
1
03_random2.in WA 17 ms 1348 KB
1
03_random3.in WA 16 ms 1304 KB
1
03_random4.in AC 14 ms 1264 KB
1
03_random5.in AC 12 ms 1348 KB
1
03_random6.in AC 16 ms 1440 KB
1
04_random1.in AC 14 ms 1268 KB
1
04_random2.in AC 11 ms 1356 KB
1
04_random3.in AC 17 ms 1436 KB
1
04_random4.in AC 17 ms 1268 KB
1
04_random5.in AC 16 ms 1352 KB
1
04_random6.in AC 13 ms 1312 KB
1
05_random1.in AC 24 ms 1396 KB
1
05_random2.in AC 23 ms 1592 KB
1
05_random3.in AC 25 ms 1656 KB
1
05_random4.in AC 26 ms 1588 KB
1
06_random1.in AC 26 ms 2928 KB
1
06_random3.in TLE 1000 ms 1332 KB
1