RT,用快读会UKE,但是把读入n那一行改成 cin >> n就A了(我知道这里快读没意义,想知道原因
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define rg register
inline int read(){
rg int x = 0, f = 1;
rg char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x * f;
}
const int N = 1e6 + 1;
int n;
int net[N];
int prenext(string a){
net[0] = 0;
int len = a.length();
for (int i = 1; i < len; ++i){
int j = net[i - 1];
while (j && a[j] != a[i]) j = net[j - 1];
if (a[j] == a[i]) net[i] = j + 1;
else net[i] = 0;
}
return net[len - 1];
}
inline void doit(){
n = read();
string b, ans;
cin >> ans;
for (int i(2); i <= n; ++i){
cin >> b;
int l = min(b.size(), ans.size());
string a = b + "#" + ans.substr(ans.size() - l, l);
b.erase(0, prenext(a));
ans += b;
}
cout << ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
//freopen("in.txt", "r", stdin);
doit();
return 0;
}