Submission #00097


ソースコード

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
168
169
170
171
172
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Myon
{
public Myon() { }
public static int Main()
{
new Myon().calc();
return 0;
}
Scanner cin;
long[] fact;
int MAX = 200005;
long mod = 1000000007;
long powmod(long a, long p)
{
long ans = 1;
long mul = a;
for (; p > 0; p >>= 1, mul = (mul * mul) % mod)
{
if ((p & 1) == 1) ans = (ans * mul) % mod;
}
return ans;
}
long calc2(long now, long a, long b)
{
now *= powmod(10, b);
now %= mod;
now += (powmod(10, b) + (mod - 1)) % mod * powmod(9, mod - 2) % mod * a;
now %= mod;
return now;
}
void calc()
{
cin = new Scanner();
int N = cin.nextInt();
Tuple<int, int>[] A = new Tuple<int, int>[N];
for (int i = 0; i < N; i++)
{
A[i] = Tuple.Create(cin.nextInt(), cin.nextInt());
}
fact = new long[MAX];
fact[0] = 1;
for (int i = 1; i < MAX; i++)
{
fact[i] = fact[i - 1] * i;
fact[i] %= mod;
}
StringBuilder sb = new StringBuilder();
long ans = 0;
long ans2 = 1;
Array.Sort(A);
if(A[0].Item1 == 0)
{
//0 pattern
int minp = -1;
int minl = -1;
int cnt = 0;
int minpos = -1;
for (int i = 0; i < A.Length; i++)
{
if (A[i].Item1 == 0) continue;
if (minp == -1)
{
minp = A[i].Item1;
minl = A[i].Item2;
cnt++;
minpos = i;
}
else if (minp == A[i].Item1 && minl == A[i].Item2) cnt++;
}
if (minpos != -1)
{
A[minpos] = Tuple.Create(10, 1);
Array.Sort(A);
N--;
ans = calc2(ans, minp, minl);
ans2 *= cnt;
}
}
int prenum = -1;
int prelen = 0;
for (int i = 0; i < N; i++)
{
if(prenum != A[i].Item1)
{
ans2 *= fact[prelen];
ans2 %= mod;
prelen = 0;
}
prelen++;
prenum = A[i].Item1;
ans = calc2(ans, A[i].Item1, A[i].Item2);
//sb.Append((char)('0' + A[i].Item1), A[i].Item2);
}
ans2 *= fact[prelen];
ans2 %= mod;
long now = 0;
string S = sb.ToString();
for (int i = 0; i < S.Length; i++)
{
now *= 10;
}
Console.WriteLine(ans);
Console.WriteLine(ans2);
}
}
class Scanner
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner()
{
s = new string[0];
i = 0;
}
public string next()
{
if (i < s.Length) return s[i++];
string st = Console.ReadLine();
while (st == "") st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return s[i++];
}
public int nextInt()
{
return int.Parse(next());
}
public long nextLong()
{
return long.Parse(next());
}
public double nextDouble()
{
return double.Parse(next());
}
}

ステータス

項目 データ
問題 0003 - repdigit
ユーザー名 chokudai
投稿日時 2017-07-07 20:56:57
言語 C#
状態 Accepted
得点 100
ソースコード長 3784 Byte
最大実行時間 578 ms
最大メモリ使用量 20156 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01_sample1.in AC 45 ms 10592 KB
1
01_sample2.in AC 41 ms 10600 KB
1
01_sample3.in AC 46 ms 12548 KB
1
02_handmake1.in AC 47 ms 12632 KB
1
02_handmake2.in AC 51 ms 10744 KB
1
02_handmake3.in AC 42 ms 10524 KB
1
02_handmake4.in AC 42 ms 10556 KB
1
02_handmake5.in AC 43 ms 10704 KB
1
02_handmake6.in AC 42 ms 12604 KB
1
02_handmake7.in AC 49 ms 8572 KB
1
02_handmake8.in AC 41 ms 10704 KB
1
02_handmake9.in AC 39 ms 12964 KB
1
03_random1.in AC 40 ms 10688 KB
1
03_random2.in AC 41 ms 10716 KB
1
03_random3.in AC 45 ms 12868 KB
1
03_random4.in AC 41 ms 10652 KB
1
03_random5.in AC 43 ms 10932 KB
1
03_random6.in AC 41 ms 10776 KB
1
04_random1.in AC 39 ms 10784 KB
1
04_random2.in AC 40 ms 10612 KB
1
04_random3.in AC 44 ms 12872 KB
1
04_random4.in AC 47 ms 10784 KB
1
04_random5.in AC 40 ms 12804 KB
1
04_random6.in AC 44 ms 10864 KB
1
05_random1.in AC 574 ms 20088 KB
1
05_random2.in AC 535 ms 17896 KB
1
05_random3.in AC 554 ms 17996 KB
1
05_random4.in AC 537 ms 18120 KB
1
06_random1.in AC 556 ms 18032 KB
1
06_random3.in AC 578 ms 20156 KB
1