MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Hackerrank_problems/Sam and substrings/solution.cpp:23–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21*/
22
23int main()
24{
25 fastio // faster I/O
26 // take input as a string due to contraints
27 string s;
28 cin>>s;
29 int n = s.size();
30 // initializing dp states
31 ll* dp =new ll[n];
32 // initializing dp[0] as the first digit
33 dp[0]=int(s[0]-'0');
34 for(int i=1;i<n;i++)
35 {
36 int key = int(s[i]-'0');
37 // recurrence step
38 dp[i]= dp[i-1]*10 + key*(i+1);
39 dp[i]%=mod;
40 }
41 ll sum=0;
42 // summing dp[i] states from 0 to n-1
43 for(int i=0;i<n;i++)
44 {
45 sum+=dp[i];
46 sum%=mod;
47 }
48 // print answer
49 cout<<sum<<endl;
50}
51

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected