记录编号 583377 评测结果 AWWWWWWWWW
题目名称 3318.[USACO19 DEC Bronze]Where Am I? 最终得分 10
用户昵称 ┭┮﹏┭┮ 是否通过 未通过
代码语言 C++ 运行时间 0.000 s
提交时间 2023-10-12 21:22:13 内存使用 0.00 MiB
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
const int N = 110;
int n;
int nx[N];
char c[N];
int main(){
    freopen("whereami.in","r",stdin);
    freopen("whereami.out","w",stdout);
    scanf("%d%s",&n,c+1);
    for(int i = 2,j = 0;i <= n;i++){
        while(j > 0 && c[i] != c[j+1])j = nx[j];
        if(c[i] == c[j+1])j++;
        nx[i] = j;
    }
    printf("%d\n",n-nx[n]);
    
    return 0;
    
}