Afişează mesaje
|
Pagini: [1] 2 3
|
11
|
infoarena - concursuri, probleme, evaluator, articole / Arhiva de probleme / Răspuns: 477 Alee
|
: Februarie 15, 2014, 15:18:11
|
si cu int i-au tot memory limit exced
in primul rand nu trebuie sa bordezi matricea. apoi ai de ales intre 2 optimizari: 1) pui short peste tot 2) schimbi citirea/scrierea. adica faci asa: freopen("alee.in","r", stdin); freopen("alee.out","w", stdout); scanf("%d%d",&n,&m);
|
|
|
12
|
infoarena - concursuri, probleme, evaluator, articole / Arhiva de probleme / Răspuns: 477 Alee
|
: Februarie 15, 2014, 13:40:19
|
de ce i-au memory limit exced pe testele 6,7,8 cu solutia #include<iostream> #include<stdio.h> FILE *f,*g; using namespace std; const int x2[4]={0,0,1,-1}; const int y2[4]={1,-1,0,0}; long long a[178][178],x1,y1,n,m,x0,y0,i,j,u,t,inceput=1,sfarsit=1; struct punct { int ls,ld,d; }; punct coada[31684],x,y; int main() { f=fopen("alee.in","r"); g=fopen("alee.out","w"); fscanf(f,"%lld%lld",&n,&m); for(i=1;i<=m;i++) { fscanf(f,"%lld%lld",&u,&t); a [t]=-1; } fscanf(f,"%lld%lld%lld%lld",&x0,&y0,&x1,&y1); for(i=0;i<=n+1;i++) { a[0]=a[n+1]=-1; a } coada[inceput].ls=x0; coada[inceput].ld=y0; coada[inceput].d=1; a[x0][y0]=1; while(inceput<=sfarsit) { x=coada[inceput]; inceput++; for(int k=0;k<4;k++) { if(a[x.ls+x2[k]][x.ld+y2[k]]==0) { a[x.ls+x2[k]][x.ld+y2[k]]=x.d+1; y.d=x.d+1; y.ls=x.ls+x2[k]; y.ld=x.ld+y2[k]; sfarsit++; coada[sfarsit]=y; if(y.ls==x1&&y.ld==y1) { fprintf(g,"%lld",a[y.ls][y.ld]); break; } } } } }
pentru ca folosesti long long
|
|
|
|