CSES - Putka Open 2015 – 5/6 - Results
Submission details
Task:Käännöt
Sender:
Submission time:2015-11-07 22:56:29 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED41
#3ACCEPTED44
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.06 s1details
#3ACCEPTED0.05 s1details
#4ACCEPTED0.04 s1details
#5ACCEPTED0.06 s1details
#6ACCEPTED0.05 s2details
#7ACCEPTED0.05 s2details
#8ACCEPTED0.06 s2details
#9ACCEPTED0.06 s2details
#10ACCEPTED0.05 s2details
#11ACCEPTED0.05 s3details
#12ACCEPTED0.07 s3details
#13ACCEPTED0.06 s3details
#14ACCEPTED0.05 s3details
#15ACCEPTED0.06 s3details

Code

#include <iostream>
using namespace std;
typedef long long ll;
const int MN = 1e5+100;
const ll MOD = 1e9+7;
ll sum1[MN];
ll sum2[MN];
ll sum3[MN];
ll getSum1(int a, int b) {
    if(b < a) return 0;
    return (sum1[b] - sum1[a-1])%MOD;
}
ll getSum2(int a, int b) {
    if(b < a) return 0;
    return (sum2[b] - sum2[a-1])%MOD;
}
ll getSum3(int a, int b) {
    if(b < a) return 0;
    return (sum3[b] - sum3[a-1])%MOD;
}
ll ex[MN];
int main() {
    string s;
    cin>>s;
    ll lol = 1;
    ex[0] = 1;
    for(int i = 1; i < MN; ++i) {
        ex[i] = ex[i-1]*10%MOD;
    }
    for(int i = 0; i < MN-1; ++i) {
        sum1[i+1] = sum1[i]*10+i+1;
        sum1[i+1] %= MOD;
        sum2[i+1] = sum2[i] + lol*(i+1);
        sum2[i+1] %= MOD;
        lol *= 10;
        lol %= MOD;
        sum3[i+1] = sum3[i]*10 + 1;
        sum3[i+1] %= MOD;
    }
    ll n = s.size();
    ll ans = 0;
    for(ll i = 1; i <= n; ++i) {
        int x = s[i-1] - '0';
        int a = i;
        int b = n-i+1;
        int c = min(a, b);
        ll d = getSum1(1, c);
        ll mid = n - 2*c+1;
        d *= ex[mid];
        d %= MOD;
        d += getSum3(1, mid)*c;
        d %= MOD;
        d *= ex[c-1];
        d %= MOD;
        d += getSum2(1, c-1);
        ans += d * x % MOD;
        ans += x * (((i-1)*i/2 + (n-i)*(n-i+1)/2)%MOD)%MOD*ex[n-i];
        ans %= MOD;
    }
    ans += MOD;
    ans %= MOD;
    cout<<ans<<'\n';
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
825864589849478186996872119675...

correct output
457966376

user output
457966376

Test 2

Group: 1

Verdict: ACCEPTED

input
191658935877461356157657491987...

correct output
176954270

user output
176954270

Test 3

Group: 1

Verdict: ACCEPTED

input
348988594526165698179722696175...

correct output
338693404

user output
338693404

Test 4

Group: 1

Verdict: ACCEPTED

input
959161872742625799336943933597...

correct output
585928712

user output
585928712

Test 5

Group: 1

Verdict: ACCEPTED

input
925429363246698689162197257943...

correct output
517617697

user output
517617697

Test 6

Group: 2

Verdict: ACCEPTED

input
972591294933975999938266397628...

correct output
667001154

user output
667001154

Test 7

Group: 2

Verdict: ACCEPTED

input
275688881195265674233697529772...

correct output
213272855

user output
213272855

Test 8

Group: 2

Verdict: ACCEPTED

input
654678934762543351831648468742...

correct output
465477034

user output
465477034

Test 9

Group: 2

Verdict: ACCEPTED

input
852895263384279396767531876338...

correct output
225052500

user output
225052500

Test 10

Group: 2

Verdict: ACCEPTED

input
257723665884149498894428498943...

correct output
169577498

user output
169577498

Test 11

Group: 3

Verdict: ACCEPTED

input
965391619923528543348143963721...

correct output
458795777

user output
458795777

Test 12

Group: 3

Verdict: ACCEPTED

input
934996116481518541954869782274...

correct output
38884659

user output
38884659

Test 13

Group: 3

Verdict: ACCEPTED

input
356521595763548549682719476371...

correct output
335143519

user output
335143519

Test 14

Group: 3

Verdict: ACCEPTED

input
691571977153731228387836644955...

correct output
504860195

user output
504860195

Test 15

Group: 3

Verdict: ACCEPTED

input
882254176987218851832315176774...

correct output
32749477

user output
32749477