#31288: c++ TLE求解


jason0713 ((ง⁼ω⁼)งꉂ(ˊᗜˋ*))


#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;cin>>n;
	int t[n],s[n],ans[n];
	for(int i=0;i<n;i++)ans[i]=-1;
	for(int i=0;i<n;i++)cin>>t[i];
	for(int i=0;i<n;i++)cin>>s[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(t[i]==s[j])ans[i]=abs(i-j);
		}
	}
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
}
#31294: Re: c++ TLE求解


r1cky (hehe)


#include
using namespace std;
int main(){
  ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;cin>>n;
	int t[n],s[n],ans[n];
	for(int i=0;i>t[i];
	for(int i=0;i>s[i];
	for(int i=0;i


時間複雜度不對啊,題目有講到這題$O(N^2)$不會過,所以你的方法不夠好

#31314: Re: c++ TLE求解


fire5386 (becaidorz)


時間複雜度不對啊,題目有講到這題$O(N^2)$不會過,所以你的方法不夠好


rickyorz