#31288: c++ TLE求解


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

學校 : 不指定學校
編號 : 184210
來源 : [61.230.27.185]
最後登入時間 :
2023-12-26 20:02:53
i164. 比對卡片(進階版) -- TOI練習賽202204新手組 | From: [125.227.14.7] | 發表日期 : 2022-07-22 15:54

#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)

學校 : 國立臺灣師範大學
編號 : 158637
來源 : [140.122.136.123]
最後登入時間 :
2024-04-25 13:42:09
i164. 比對卡片(進階版) -- TOI練習賽202204新手組 | From: [1.34.88.173] | 發表日期 : 2022-07-23 07:36

#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)

學校 : 國立清華大學
編號 : 115822
來源 : [140.114.217.8]
最後登入時間 :
2024-04-13 22:06:23
i164. 比對卡片(進階版) -- TOI練習賽202204新手組 | From: [114.25.64.248] | 發表日期 : 2022-07-23 15:02

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


rickyorz

 
ZeroJudge Forum