Untitled
raw download clone
C
views 31
,
size 1275 b
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10000001
#define MOD 1000000007
#define ll long long int

char str[N];
char temp[N];

void substr(ll st, ll en)
{
    ll count = 0;
    for(ll i=st; i<en;i++){
        temp[count++] = str[i];
    }
}

int main(){
    ll t, x, s_len;
    ll l = 0;

    scanf("%lld", &t);
    while(t--){
        scanf("%lld", &x);
        scanf("%s", str);

        s_len = l = strlen(str);

        for(ll i=1; i<=x; i++){
            ll paste = (str[i-1]-'0');
            ll add = (((paste-1)%MOD)*((l-i)%MOD))%MOD;
            l = (l%MOD + add%MOD)% MOD;
            //printf("paste = %lld , l = %3lld , add = %3lld\n", paste, l, add);

            if(s_len <= x && paste > 1){
                // substr(i, s_len);
                // substr Àò¨ú str(i~end)ªº¤l¦r¦ê
                strncpy(temp, str+i, s_len-i+1);

                ll t_len = strlen(temp);
                for(ll j=0; j<(paste-1) && s_len <= x; j++){
                    strcat(str, temp);
                    s_len += t_len;
                }
                //printf("%s: %s\n", temp, str);
            }

            if(l < 0)   l+= MOD;
        }

        printf("%lld\n", l);
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.