|
|
вернуться в форумCrash <acces violant> on test 3! Pls help Why Crash (acces violant) I use vector < map <int,int> > ! Are the problem in it? P.S Sorry for my bad English #include <cstdio> #include <vector> #include <algorithm> #include <map> #include <iostream> #include <cstdlib> using namespace std; struct neww{ int x,n; }; int abss(int x) { if (x>=0) return x; else return (-x); } bool funcsort(neww a, neww b) { if (a.x < b.x) return true; else return false; } int main() { int n,i,j,x,maxn; neww a[2200]; scanf("%d",&n); vector < map <int,int> > b(12000); vector < map <int,int> > pi(12000); vector < map <int,int> > pj(12000);
for (i = 0; i < n; ++i) { scanf("%d",&a[i].x); a[i].n = i + 1; } sort(a,a+n,funcsort); if (n == 1) { printf("1\n"); printf("%d\n",1); exit(0); }
for (i = n - 1; i >= 0; --i) { for (j = n - 1; j > i; --j) if (a[j].x-a[i].x > 0) { b[i][a[j].x-a[i].x] = max(b[i][a[j].x-a[i].x],b[j][a[j].x-a[i].x] + 1); if (b[i][a[j].x - a[i].x] = b[j][a[j].x-a[i].x] + 1) { pi[i][a[j].x-a[i].x] = j; pj[i][a[j].x-a[i].x] = a[j].x - a[i].x; } } } maxn = 0; int numb,ost; for (i = 0; i < n; ++i) for (j = i; j < n; ++j) if (b[i][abss(a[i].x - a[j].x)] > maxn) { maxn = b[i][abss(a[i].x-a[j].x)]; numb = i; ost = abss(a[i].x - a[j].x); } printf("%d\n",maxn+1); printf("%d",a[numb].n); while (maxn) { int nm = pi[numb][ost]; int ot = pj[numb][ost];
printf(" %d",a[nm].n);
numb = nm; ost = ot; --maxn; } printf("\n");
} Edited by author 17.06.2011 01:42 |
|
|