File tree Expand file tree Collapse file tree 1 file changed +9
-26
lines changed
Math/2954.Count-the-Number-of-Infection-Sequences Expand file tree Collapse file tree 1 file changed +9
-26
lines changed Original file line number Diff line number Diff line change @@ -2,56 +2,39 @@ using LL = long long;
22class Solution {
33 LL power[100005 ];
44 LL fact[100005 ];
5- LL M = 1e9 +7 ;
65 LL mod = 1e9 +7 ;
76public:
87 int numberOfSequence (int n, vector<int >& sick)
98 {
109 power[0 ] = 1 ;
1110 for (int i=1 ; i<=n; i++)
12- power[i] = power[i-1 ]*2 % M ;
11+ power[i] = power[i-1 ]*2 % mod ;
1312
1413 fact[0 ] = 1 ;
1514 for (int i=1 ; i<=n; i++)
16- fact[i] = fact[i-1 ]*i % M ;
15+ fact[i] = fact[i-1 ]*i % mod ;
1716
1817 vector<int >groups;
1918 for (int i=0 ; i<sick.size (); i++)
2019 {
2120 if (i==0 )
22- {
23- if (sick[0 ]!=0 )
24- groups.push_back (sick[i]);
25- }
21+ groups.push_back (sick[i]);
2622 else
27- {
28- if (sick[i]-sick[i-1 ]-1 >0 )
29- groups.push_back (sick[i]-sick[i-1 ]-1 );
30- }
31-
23+ groups.push_back (sick[i]-sick[i-1 ]-1 );
3224 }
33- if (sick.back ()!=n-1 )
34- groups.push_back (n-1 -sick.back ());
35-
36- // for (int x: groups) cout<<x<<" "; cout<<endl;
25+ groups.push_back (n-1 -sick.back ());
3726
3827 int total = accumulate (groups.begin (), groups.end (), 0 );
3928
4029 LL ret = fact[total];
41- for (int x: groups)
42- {
43- // cout<<fact[x]<<endl;
44- ret = ret * inv (fact[x]) % M;
45- }
46-
47- // cout<<ret<<endl;
48-
49-
30+ for (int x: groups)
31+ ret = ret * inv (fact[x]) % mod;
32+
5033 for (int i=1 ; i<sick.size (); i++)
5134 {
5235 int x = sick[i]-sick[i-1 ]-1 ;
5336 if (x>0 )
54- ret = ret * power[x-1 ] % M ;
37+ ret = ret * power[x-1 ] % mod ;
5538 }
5639
5740 return ret;
You can’t perform that action at this time.
0 commit comments