[分析题目] Jzoj P5860 荒诞

Description

 

Input

Output

 

Sample Input

输入1:
7
ABC

输入2:
5
AAAAAAAAAA
 

Sample Output

输出1:
14

输出2:
385
 

Data Constraint

 

Hint

题解

  • 题目说一字符串的第i个前缀就是第1~i依次连起来
  • 那不就说第i个前缀的位置就是i
  • 那么问题就转成了1~n的平方和

代码

 1 #include <cstdio>
 2 #include <cstring>
 3 using namespace std;
 4 long long n,m;
 5 char s[1000010];
 6 long long ans,mo=1e9+7;
 7 int main()
 8 {
 9     scanf("%lld",&m); scanf("%s",s+1);
10     n=strlen(s+1);
11     for (long long i=1;i<=n;i++) (ans+=i%mo*i%mo)%=mo;
12     printf("%lld",ans);
13 }

猜你喜欢

转载自www.cnblogs.com/Comfortable/p/9649787.html