E. Stupid Submissions (暴力模拟)
https://codeforces.com/gym/101972/problem/E
When Abed gets a wrong answer on test x (x ≤ n), he can see all the tests up to test number x. If Abed gets accepted, he can see all the tests.
Each test can be either small or big. Abed can see the entire test only if it is small. If the test is big, Abed can see it partially. All the sample tests are small.
A submission made by Abed is called stupid if he got a wrong answer on a small test that he can see it fully.You are given a list of submissions made be Abed, your task is to count how many stupid submission Abed has made.
The first k tests are called sample tests. These tests are visible in the problem statement and a user can see them all.
开始可视化的样例有k个
n个样例 m次提交
如果该wa点已经可视化,并且为small,则认为是1次stupid,wa的位置如果比当前可视化的多,则wa后可视化的范围变大到wa的位置,vis数组标记该wa点之前是否wa过,如果wa过并且为small,认为是1次stupid,ans++;
AC同样考虑 AC之后可能又会wa 可视化范围此时为1-n 下次wa的位置为S ans++
2
5 4 2
S S B S B
W 3
W 4
W 4
A
4 3 2
S S B B
W 1
W 2
W 3
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+5;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll gcd(ll a,ll b)
{
return b!=0?gcd(b,a%b):a;
}
char a[maxn];
int vis[maxn];
int main()
{
IO;
ll t,n,m,k,p,ans=0;
char ch;
cin>>t;
while(t--)
{
ans=0;
memset(vis,0,sizeof vis);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=k;i++)
vis[k]=1;
while(m--)
{
cin>>ch;
if(ch=='W')
{
cin>>p;
if(p>=1 && p<=k)//当前可视化的
{
if(a[p]=='S')
ans++;
}
else if(p>k)
{
k=p;
if(vis[p]==0)//这个wa点没wa过 第一次wa
vis[p]=1;
else//又是这个wa点
{
if(a[p]=='S')//如果小样例 stupid
ans++;
}
}
}
else //ac了之后又提交wa
k=n;//可视化范围变到n了
}
cout<<ans<<endl;
}
return 0;
}
H 暴力枚举
http://codeforces.com/gym/101972/problem/H
注意预处理出a串长k的首尾字母去重放入set 26*26种情况
set<pair<char,char> > ss;
多组输入不清空set会wa 或者每次定义放入多组输入
在b中寻找子串 预处理出的所有情况枚举
如果此首尾相同 如kkd dkd
a串长1的子串 k,d
b串中找首尾相同发现 倒着找d此时出现次数是几则+几
自己到自己 自己到相同的别人
如果首尾不同 只取尾部总个数 到start时加上所有尾出现次数为此次num累加的结果
#include<bits/stdc++.h>
#include<set>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
ll gcd(ll a,ll b)
{
return b!=0?gcd(b,a%b):a;
}
set<pair<char,char> > ss; //最多首尾26*26种可能
int main()
{
IO;
int t,n,m,k;
string a,b;
cin>>t;
while(t--)
{
ss.clear();//多组输入清空
cin>>n>>m>>k;//a的长为k的子串的首尾字母 b首尾字母与其相同的子串个数
cin>>a;
cin>>b;
//预处理a长k子串
for(int i=0;i<n-k+1;i++)
{
ss.insert(mp(a[i+0],a[i+k-1]));//长为k
}
ll num=0;
for(auto p:ss) //枚举首尾
{
char s=p.first,e=p.second;
ll nume=0;//每一种首尾计数
if(s!=e)
{
for(int i=m-1;i>=0;i--)//尾部计数
{
if(b[i]==e)
nume++;
else if(b[i]==s)
{
num+=nume;
}
}
}
else //首尾相等
{
for(int i=m-1;i>=0;i--)
{
if(b[i]==e)
{
nume++;
num+=nume;
}
}
}
}
cout<<num<<endl;
}
}