Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:把数组改成vector后从runtime error变成wrong answer了,哪里错了,求助In Reply To:把数组改成vector后从runtime error变成wrong answer了,哪里错了,求助 Posted by:LinXiuKe at 2017-04-08 23:01:41 > #include <iostream> > #include <algorithm> > #include <vector> > #include <set> > #include <map> > using namespace std; > > int solve(int P, vector<int> a) > { > set<int> all; > int i, n; > > for(i = 0; i < P; i++) > all.insert(a[i]); > > n = all.size(); > > int s = 0, t = 0, num = 0; > map<int, int> count; > int res = P; > > while(true) > { > while(t < P && num < n) > if(count[a[t++]]++ == 0) > num++; > > if(num < n) > break; > > res = min(res, t-s); > > if(--count[a[t++]] == 0) > num--; > } > > return res; > } > > int main(int argc, char *argv[]) > { > int P, x; > vector<int> a; > scanf("%d", &P); > for(int i = 0; i < P; i++) > { > scanf("%d", &x); > a.push_back(x); > } > > > int res = solve(P, a) ; > printf("%d\n", res); > > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator