求助,为何O(n)会TLE
查看原帖
求助,为何O(n)会TLE
368284
い中野三玖い楼主2022/9/12 12:11

代码如下:

#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*=f;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');  
}
const int N=1e5;
int n,a[N*5],b[N*5],s,s1;
signed main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	for(int i=1;i<=n;i++)
	{
		if(a[i]==b[i]) s++;
		if(a[n-i+1]==b[i]) s1++;
	}
	if(s1-1>=s) cout<<n-s1+1<<endl;
	else cout<<n-s<<endl;
	return 0;
}
2022/9/12 12:11
加载中...