Submission #1591487
Source Code Expand
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
const int N=105,MOD=998244353,H0=19260817,H1=2333;
char s[N],t[N];
ll f[N][2],g[N][2];
int n,ans;
int main()
{
scanf("%d",&n);
scanf("%s",s+1);
scanf("%s",t+1);
ll t0=1,t1=1;
for(int i=n;i;i--)
{
f[i][0]=(f[i+1][0]+t0*s[i])%MOD;
f[i][1]=(f[i+1][1]+t1*s[i])%MOD;
t0=t0*H0%MOD;
t1=t1*H1%MOD;
}
for(int i=1;i<=n;i++)
{
g[i][0]=(g[i-1][0]*H0+t[i])%MOD;
g[i][1]=(g[i-1][1]*H1+t[i])%MOD;
}
ans=0;
for(int i=1;i<=n;i++)
if(f[i][0]==g[n-i+1][0] && f[i][1]==g[n-i+1][1])
{
ans=n-i+1;
break;
}
printf("%d\n",n*2-ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Prefix and Suffix |
User |
Demerzel_IV |
Language |
C++14 (GCC 5.4.1) |
Score |
200 |
Code Size |
670 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
256 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:11:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:12:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s+1);
^
./Main.cpp:13:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",t+1);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
200 / 200 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
AC |
1 ms |
256 KB |
1_02.txt |
AC |
1 ms |
256 KB |
1_03.txt |
AC |
1 ms |
256 KB |
1_04.txt |
AC |
1 ms |
256 KB |
1_05.txt |
AC |
1 ms |
256 KB |