Than0th's blog

By Than0th, history, 2 months ago, In English

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<int>>adj(N);
vector<vector<int>>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);
    }
    vector<int>v(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';
}

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By Than0th, 4 years ago, In English

Months ago i solved a problem but i cant remember its name the task description is about a soda can's where there are a group of friends consist of five friends in a line to buy the soda and after the first person buy a soda he go to the end of the line and be doubled, hope you help me plz, sorry for bad description :)

Full text and comments »

  • Vote: I like it
  • +2
  • Vote: I do not like it

By Than0th, history, 4 years ago, In English

As I remember, the educational round was going to be held today.

Full text and comments »

  • Vote: I like it
  • +27
  • Vote: I do not like it