标签:may main ini code clipboard return char tput 链接
https://codeforces.com/contest/1281/problem/C
outputstandard output
We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by si.
There is one cursor. The cursor‘s location ? is denoted by an integer in {0,…,|s|}, with the following meaning:
If ?=0, then the cursor is located before the first character of s.
If ?=|s|, then the cursor is located right after the last character of s.
If 0<?<|s|, then the cursor is located between s? and s?+1.
We denote by sleft the string to the left of the cursor and sright the string to the right of the cursor.
We also have a string c, which we call our clipboard, which starts out as empty. There are three types of actions:
The Move action. Move the cursor one step to the right. This increments ? once.
The Cut action. Set c←sright, then set s←sleft.
The Paste action. Append the value of c to the end of the string s. Note that this doesn‘t modify c.
The cursor initially starts at ?=0. Then, we perform the following procedure:
Perform the Move action once.
Perform the Cut action once.
Perform the Paste action s? times.
If ?=x, stop. Otherwise, return to step 1.
You‘re given the initial string s and the integer x. What is the length of s when the procedure stops? Since this value may be very large, only find it modulo 109+7.
It is guaranteed that ?≤|s| at any time.
模拟操作到x的长度,剩下的遍历一遍算值,居然不超时。。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
int main()
{
int t;
cin >> t;
while(t--)
{
int x;
string s;
cin >> x >> s;
int l = 1;
while((int)s.size() < x)
{
int len = s.size();
for (int i = 1;i < (int)s[l-1]-'0';i++)
s += s.substr(l, len-l);
l++;
}
LL ans = s.size()%MOD;
for (int i = l;i <= x;i++)
{
int tmp = s[i-1]-'0';
ans = (ans+(ans-i)*(tmp-1)%MOD+MOD)%MOD;
}
cout << ans%MOD << endl;
}
return 0;
}
Codeforces Round #607 (Div. 2) C. Cut and Paste
标签:may main ini code clipboard return char tput 链接
原文地址:https://www.cnblogs.com/YDDDD/p/12104853.html