Submission #00356


ソースコード

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;
const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }
typedef vector<vector<lint> > matrix;
matrix e, A;
int n;
vi a, b;
lint mod_pow(lint a, lint x, int p = 1e9 + 7) {
lint ret = 1;
for (lint i = 1ll << 60; i; i >>= 1) {
ret *= ret;
ret %= p;
if (x & i) { ret *= a; ret %= p; }
}
return ret;
}
vector<lint> fact(1, 1);
lint Fact(lint n, int p = 1e9 + 7) {
if (n == 0) return 1;
if (fact.size() <= n) {
fact.push_back(Fact(n - 1) * n % p);
}
return fact[n];
}
void makee(int n) {
e.clear();
e.resize(n);
rep(i, n) rep(j, n) {
lint E = 1;
lint Z = 0;
e[i].push_back(i == j ? E : Z);
}
}
void makeA(int n) {
A.clear();
A.resize(n);
rep(i, n) A[i].resize(n);
A[0][0] = 1; A[0][1] = 0;
A[1][0] = 1; A[1][1] = 10;
}
matrix product(matrix a, matrix b) {
matrix ret;
ret.resize(a.size());
for (int i = 0; i < a.size(); i++) ret[i].resize(b[0].size());
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < b[0].size(); j++) {
for (int k = 0; k < a[0].size(); k++) {
ret[i][j] += a[i][k] * b[k][j];
ret[i][j] %= mod;
}
ret[i][j] %= mod;
}
}
return ret;
}
matrix po(matrix a, lint b) {
if (b == 0) return e;
matrix z = po(a, b / 2);
z = product(z, z);
if (b & 1) z = product(z, a);
return z;
}
lint number(int a, lint b) {
matrix x(2);
x[0].pb(a);
x[1].pb(0);
matrix ans = product(po(A, b), x);
return ans[1][0];
}
signed main() {
cin >> n;
rep(i, n) { a.pb(in()); b.pb(in()); }
vector<int> num[10];
rep(i, n) {
num[a[i]].pb(b[i]);
}
rep(i, 10) sort(all(num[i]));
makee(2);
makeA(2);
lint res1 = 0;
lint res2 = 1;
// 使われていない最小のインデックス
int used[10] = {0};
// 1以上の最小の数字を前に
for (int i = 1; i < 10; ++i) {
if (num[i].size()) {
lint a = num[i][0];
int cnt = 0;
rep(j, num[i].size()) {
if (num[i][j] == a) {
cnt++;
continue;
}
break;
}
res1 = number(i, num[i][0]);
used[i] = 1;
res2 = cnt;
break;
}
}
if (res1 == 0) {
res2 = 1;
} else {
rep(i, 10) {
lint b = 0;
for (int j = used[i]; j < num[i].size(); ++j) {
b += num[i][j];
}
res1 = (res1 * mod_pow(10, b)) % mod;
res1 += number(i, b);
res1 %= mod;
res2 *= Fact(num[i].size() - used[i]);
res2 %= mod;
}
}
print(res1);
print(res2);
}

ステータス

項目 データ
問題 0003 - repdigit
ユーザー名 Luzzle0119
投稿日時 2017-07-07 22:58:16
言語 C++11
状態 Wrong Answer
得点 0
ソースコード長 3653 Byte
最大実行時間 71 ms
最大メモリ使用量 7624 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01_sample1.in AC 15 ms 604 KB
1
01_sample2.in AC 16 ms 572 KB
1
01_sample3.in AC 13 ms 668 KB
1
02_handmake1.in AC 12 ms 512 KB
1
02_handmake2.in AC 14 ms 608 KB
1
02_handmake3.in AC 48 ms 580 KB
1
02_handmake4.in AC 13 ms 544 KB
1
02_handmake5.in AC 10 ms 508 KB
1
02_handmake6.in AC 13 ms 476 KB
1
02_handmake7.in AC 12 ms 572 KB
1
02_handmake8.in AC 16 ms 672 KB
1
02_handmake9.in AC 13 ms 512 KB
1
03_random1.in AC 14 ms 608 KB
1
03_random2.in AC 11 ms 580 KB
1
03_random3.in AC 14 ms 680 KB
1
03_random4.in AC 14 ms 524 KB
1
03_random5.in AC 13 ms 496 KB
1
03_random6.in AC 15 ms 588 KB
1
04_random1.in AC 11 ms 684 KB
1
04_random2.in AC 12 ms 648 KB
1
04_random3.in AC 13 ms 616 KB
1
04_random4.in WA 12 ms 712 KB
1
04_random5.in WA 14 ms 680 KB
1
04_random6.in WA 10 ms 648 KB
1
05_random1.in AC 54 ms 2652 KB
1
05_random2.in AC 52 ms 2540 KB
1
05_random3.in AC 54 ms 2684 KB
1
05_random4.in AC 54 ms 2672 KB
1
06_random1.in AC 71 ms 7624 KB
1
06_random3.in WA 57 ms 1968 KB
1