Submission #00132


ソースコード

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
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;
template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
using mat = vector<vector<ll> >;
const ll mod = 1e9+7;
mat e;
void makee(int n) {
e.clear();
e.resize(n);
REP(i, n) REP(j, n) {
e[i].push_back(i == j);
}
}
mat mul(mat &a, mat &b){
mat res(a.size(), vector<ll>(b[0].size()));
REP(i, a.size()){
REP(k, b.size()){
REP(j, b[0].size()){
res[i][j] = (res[i][j]+a[i][k]*b[k][j])%mod;
}
}
}
return res;
}
mat pow(mat a, ll n){
mat res = a;
if(n == 0) return e;
if(n % 2){
res = pow(a, n-1);
return mul(a, res);
}
res = pow(a, n/2);
return mul(res, res);
}
ll number(ll a, ll b){
mat base(2, vector<ll>(2)); // ここで333333.....みたいなのを作り出したい おk
mat latte(2, vector<ll>(1));
base[0][0] = 1; base[0][1] = 0;
base[1][0] = 1; base[1][1] = 10;
latte[0][0] = a; latte[1][0] = 0; //あってますか あってそう
mat beet = pow(base, b);
mat res = mul(beet, latte);
return res[1][0];
}
ll powm(ll a, ll n){
ll res;
if(n == 0) return 1;
if(n%2) return (a * powm(a, n-1))%mod;
res = powm(a, n/2);
return (res*res)%mod;
}
ll fact[114514] = {};
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
vector<int> parts[10];
cin >> N;
ll res = 0, rn = 0;
REP(i, N){
int a, b;
cin >> a >> b;
parts[a].push_back(b);
}
makee(2);
fact[0] = 1;
FOR(i, 1, 114514)
fact[i] = (fact[i-1]*i)%mod;
REP(i, 10)
sort(all(parts[i]));
int used = 0;
FOR(i, 1, 10){
int cnt = 0;
if(parts[i].size()){
REP(j, parts[i].size()){
if(parts[i][j] == parts[i][0])
cnt++;
}
rn = number(i, parts[i][0]);
res = cnt;
used = i;
break;
}
}
if(res == 0){
cout << 0 << endl << 1 << endl;
return 0;
}
REP(i, 10){
ll cnt = 0;
REP(j, parts[i].size()){
cnt += parts[i][j];
}
if(used == i){
res *= fact[parts[i].size()-1];
cnt -= parts[i][0];
}else if(parts[i].size()){
res *= fact[parts[i].size()];
}
res %= mod;
rn = (rn * powm(10, cnt))%mod;
rn = (rn + number(i, cnt))%mod;
}
cout << rn << endl;
cout << res << endl;
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01_sample1.in AC 14 ms 1376 KB
1
01_sample2.in AC 13 ms 1332 KB
1
01_sample3.in AC 16 ms 1288 KB
1
02_handmake1.in AC 18 ms 1376 KB
1
02_handmake2.in AC 15 ms 1464 KB
1
02_handmake3.in AC 25 ms 1548 KB
1
02_handmake4.in AC 17 ms 1504 KB
1
02_handmake5.in AC 12 ms 1588 KB
1
02_handmake6.in AC 12 ms 1420 KB
1
02_handmake7.in AC 14 ms 1496 KB
1
02_handmake8.in AC 17 ms 1444 KB
1
02_handmake9.in AC 13 ms 1388 KB
1
03_random1.in AC 12 ms 1476 KB
1
03_random2.in AC 11 ms 1436 KB
1
03_random3.in AC 15 ms 1396 KB
1
03_random4.in AC 14 ms 1352 KB
1
03_random5.in AC 15 ms 1436 KB
1
03_random6.in AC 11 ms 1520 KB
1
04_random1.in AC 12 ms 1480 KB
1
04_random2.in AC 14 ms 1560 KB
1
04_random3.in AC 13 ms 1516 KB
1
04_random4.in WA 18 ms 1476 KB
1
04_random5.in WA 13 ms 1552 KB
1
04_random6.in WA 13 ms 1632 KB
1
05_random1.in AC 32 ms 2224 KB
1
05_random2.in AC 32 ms 2156 KB
1
05_random3.in AC 28 ms 2208 KB
1
05_random4.in AC 29 ms 2244 KB
1
06_random1.in AC 26 ms 2172 KB
1
06_random3.in AC 31 ms 2248 KB
1