아래 코드를 보면서 20분동안 왜 안될까 고민한게 ㄹㅈㄷ
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll arr[200005];
ll tenth[200005];
ll two[200005];
ll F[200005];
ll f(int cnt){
if(!cnt) return 0;
return F[cnt-1];
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
string s; cin>>s;
int n = s.length();
for(int i=0; s[i]; i++) arr[i+1] = s[i]-'0';
two[0] = tenth[0] = 1;
F[0] = 1;
for(int i=1; i<=200000; i++){
two[i] = two[i-1]*2; two[i]%=mod;
tenth[i] = tenth[i-1]*10; tenth[i]%=mod;
F[i] = F[i-1]*2+tenth[i];
F[i]%=mod;
}
ll ans = 0;
for(int i=1; i<=n; i++){
ll sum = arr[i]*two[i-1]; sum%=mod;
sum*=(f(n-i)+tenth[n-i])%mod;
ans+=sum%mod;
ans%=mod;
}
cout<<ans%mod;
}
댓글 0