NC222117. 喵喵喵
描述
输入描述
第一行是一个只包含小写字母的字符串。
第二行为一个正整数,代表技能发动的轮数。
第三行为一个长度为的、仅包含大写字母'N'和小写字母'n'的字符串,代表小喵和小小喵的操作。'N'代表小喵操作一次,'n'代表小小喵操作一次。
输出描述
输出最终字符串长度对取模的值。
示例1
输入:
nyany 2 Nn
输出:
6
说明:
最开始的字符串是nyany。C++ 解法, 执行用时: 61ms, 内存消耗: 4204K, 提交时间: 2021-06-01 20:17:48
#include<bits/stdc++.h> using namespace std; string s, t, k; long long n, ya, other, mod = 1e9+7; int main() { cin >> s >> k >> t; for(int i = 0; s[i]; i++) if(s[i] == 'n') n++; else if(s[i] == 'y' && s[i+1] == 'a') ya++; other = s.size() - n - 2*ya; for(auto c : t) if(c == 'N') ya = (ya + n) % mod; else n = (n + ya) % mod, ya = 0; cout << (n + 2*ya + other) % mod; }
pypy3 解法, 执行用时: 112ms, 内存消耗: 24704K, 提交时间: 2021-06-02 00:30:53
M = 1000000007 s = input() l = len(s) n = s.count('n') ya = s.count('ya') input(); for ch in input(): if ch == 'N': ya += n l += 2*n else: n += ya l -= ya ya = 0 l %= M n %=M ya %= M print(l)
Python3 解法, 执行用时: 341ms, 内存消耗: 13516K, 提交时间: 2021-06-01 21:11:22
a=input() n=int(input()) x=list(input()) s1=a.count('n') s2=a.count('ya') length=len(a) length-=s1+s2*2 for i in x: if i=='N': s2=(s1+s2)%int(1e9+7) else: s1=(s2+s1)%int(1e9+7) s2=0 print((length+s1+s2*2)%int(1e9+7))