社区讨论
关于本题数据正确性的疑问
P14363[CSP-S 2025] 谐音替换参与者 3已保存回复 16
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 16 条
- 当前快照
- 1 份
- 快照标识符
- @mhiy8hbb
- 此快照首次捕获于
- 2025/11/03 17:40 4 个月前
- 此快照最后确认于
- 2025/11/03 17:45 4 个月前
对于第一次提交,我的代码如下
CPP#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const long long inf = 1e18;
const long long mod = 998244353;
int n , m;
string x[200005] , y[200005];
map<pair<string , string> , vector<int> >a;
bool check(string s1 , string s2)
{
int cnt = 0;
for(int i = 0 ; i < s1.size() ; i++)
{
if(s1[i] == s2[cnt])cnt++;
else cnt = 0;
if(cnt == s2.size())return 1;
}
return 0;
}
signed main()
{
cin.tie(0) , cout.tie(0);
ios::sync_with_stdio(0);
// freopen("ce.in" , "r" , stdin);
// freopen("ce.out" , "w" , stdout);
cin>>n>>m;
string xx , yy;
int l , r;
for(int i = 1 ; i <= n ; i++)
{
xx = "" , yy = "";
cin>>x[i]>>y[i];
l = 0 , r = x[i].size();
for(l = 0 ; l < r ; l++)if(x[i][l] != y[i][l])break;
for(r = x[i].size() ; r > l ; r--)if(x[i][r] != y[i][r])break;
for(int j = l ; j <= r ; j++)xx += x[i][j] , yy += y[i][j];
a[make_pair(xx , yy)].push_back(i);
}
string sx , sy;
int ans;
for(int i = 1 ; i <= m ; i++)
{
cin>>sx>>sy;
ans = 0;
xx = "" , yy = "";
l = 0 , r = sx.size();
if(sx.size() != sy.size())
{
cout<<0<<endl;
continue;
}
for(l = 0 ; l < r ; l++)if(sx[l] != sy[l])break;
for(r = sx.size() ; r > l ; r--)if(sx[r] != sy[r])break;
for(int j = l ; j <= r ; j++)xx += sx[j] , yy += sy[j];
for(int j : a[make_pair(xx , yy)])
{
if(check(sx , x[j]))ans++;
}
cout<<ans<<endl;
}
return 0;
}
对于第二次提交,我的代码如下
CPP#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const long long inf = 1e18;
const long long mod = 998244353;
int n , m;
string x[200005] , y[200005];
map<pair<string , string> , vector<int> >a;
bool check(string s1 , string s2)
{
int cnt = 0;
for(int i = 0 ; i < s1.size() ; i++)
{
if(s1[i] == s2[cnt])cnt++;
else cnt = 0;
if(cnt == s2.size())return 1;
}
return 1;
}
signed main()
{
cin.tie(0) , cout.tie(0);
ios::sync_with_stdio(0);
// freopen("ce.in" , "r" , stdin);
// freopen("ce.out" , "w" , stdout);
cin>>n>>m;
string xx , yy;
int l , r;
for(int i = 1 ; i <= n ; i++)
{
xx = "" , yy = "";
cin>>x[i]>>y[i];
l = 0 , r = x[i].size();
for(l = 0 ; l < r ; l++)if(x[i][l] != y[i][l])break;
for(r = x[i].size() ; r > l ; r--)if(x[i][r] != y[i][r])break;
for(int j = l ; j <= r ; j++)xx += x[i][j] , yy += y[i][j];
a[make_pair(xx , yy)].push_back(i);
}
string sx , sy;
int ans;
for(int i = 1 ; i <= m ; i++)
{
cin>>sx>>sy;
ans = 0;
xx = "" , yy = "";
l = 0 , r = sx.size();
if(sx.size() != sy.size())
{
cout<<0<<endl;
continue;
}
for(l = 0 ; l < r ; l++)if(sx[l] != sy[l])break;
for(r = sx.size() ; r > l ; r--)if(sx[r] != sy[r])break;
for(int j = l ; j <= r ; j++)xx += sx[j] , yy += sy[j];
for(int j : a[make_pair(xx , yy)])
{
if(check(sx , x[j]))ans++;
}
cout<<ans<<endl;
}
return 0;
}
/*
*/
两次结果中代码不同点仅在于第一份代码中check函数是处于生效状态,第二份代码中我将check无效化了。然而,check在无效化后反而通过了#6。
注:check函数用于检测 被代替的字符串 是否完整的出现在了 给出的询问字符串中 。
回复
共 16 条回复,欢迎继续交流。
正在加载回复...