Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

把数组改成vector后从runtime error变成wrong answer了,哪里错了,求助

Posted by LinXiuKe at 2017-04-08 23:01:41 on Problem 3320
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator