I need help submetting this probleme on U

Правка en2, от Than0th, 2026-07-17 09:54:31

the issue:

Runtime error or memory limit exceeded on sample input case -- details below Your output file fenceplan.out:

The correct answer: 10

probleme link:

https://usaco.org/index.php?page=viewproblem2&cpid=944

this is my code:

include <bits/stdc++.h>

define tests ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t; cin>>t; while(t--)

using namespace std; typedef long long ll;

define yes cout<<"YES\n";

define no cout<<"NO\n";

define loop(i,j,k) for(int i = j; i < k; i++)

//I SEE YOU :)

/*freopen("fenceplan.out", "r", stdin); freopen("fenceplan.out", "w", stdout);*/ //blyat const int N=100000; bool visited[N]; vector<vector>adj(N); vector<vector>con; void dfs(int s,int co) { if (visited[s]) return; con[co].push_back(s); visited[s] = true; for (auto u: adj[s]) { dfs(u,co); } } int main() { freopen("fenceplan.out", "r", stdin); freopen("fenceplan.out", "w", stdout); int n,m,a,b,co=-1,ans=INT_MAX; cin>>n>>m; int arr[n][2]; for(int i=0; i<n; i++) cin>>arr[i][0]>>arr[i][1]; for(int i=0; i<m; i++) { cin>>a>>b; adj[a-1].push_back(b-1); adj[b-1].push_back(a-1); } vectorv(0); for(int i=0; i<n; i++) { if(visited[i]) continue; co++; con.push_back(v); dfs(i,co); } for(int i=0;i<N;i++) { if(con[i].size()==0) break; int maxx=0,maxy=0,minx=INT_MAX,miny=INT_MAX; for(int j=0;j<con[i].size();j++) { maxx=max(maxx,arr[con[i][j]][0]); maxy=max(maxy,arr[con[i][j]][1]); minx=min(minx,arr[con[i][j]][0]); miny=min(miny,arr[con[i][j]][1]); } ans=min(ans,(maxx-minx+maxy-miny)*2); } cout<<ans<<'\n'; }

Теги help me

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский Than0th 2026-07-17 09:58:43 4
en5 Английский Than0th 2026-07-17 09:58:02 14 Tiny change: 'Runtime er' -> 'The issue:\n\nRuntime er'
en4 Английский Than0th 2026-07-17 09:57:29 43
en3 Английский Than0th 2026-07-17 09:55:55 8
en2 Английский Than0th 2026-07-17 09:54:31 22
en1 Английский Than0th 2026-07-17 09:54:00 1969 Initial revision (published)