Editorial for Siêu trộm KID và Mật khẩu đêm Trung thu!
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của ladpro98
#include <bits/stdc++.h> #define long long long const int N = 1000006; const int MOD = 1000000007; using namespace std; char s[N]; long P[N], H[N], Sh[N]; int main() { scanf("%s", s + 1); int n = strlen(s + 1); P[0] = 1; for(int i = 1; i <= n; i++) P[i] = (10ll * P[i - 1]) % MOD; H[0] = 0; for(int i = 1; i <= n; i++) H[i] = (10ll * H[i - 1] + s[i] - '0') % MOD; for(int i = 1; i <= n; i++) Sh[i] = (Sh[i - 1] + H[i]) % MOD; long add = 0; for(int i = 1; i <= n; i++) add = (add + Sh[n] + MOD - Sh[i - 1]) % MOD; long sub = 0; for(int i = 1; i <= n; i++) sub = (sub + P[i] * Sh[n - i]) % MOD; long res = (add + MOD - sub) % MOD; cout << res; return 0; }
Code mẫu của skyvn97
#include<cstdio> #include<cstring> #include<iostream> #define MAX 1001000 #define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;i=i+1) #define REP(i,n) for (int i=0,_n=(n);i<_n;i=i+1) using namespace std; const int mod=(int)1e9+7; char a[MAX]; int n; int main(void) { int res=0; scanf("%s",a+1); n=strlen(a+1); int s=0; FOR(i,1,n) { s=(10LL*s+1LL*i*(a[i]-'0'))%mod; res=(res+s)%mod; } printf("%d",res); return 0; }
Comments