답안 #920076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920076 2024-02-02T03:20:29 Z Faisal_Saqib Lottery (CEOI18_lot) C++17
45 / 100
3000 ms 10780 KB
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int N=1e4+1;
int a[N],l,n,cpy[N];
bool posa=0;
map<int,int> ans[N];
vector<vector<int>> hp;
void level_up()
{
	if(posa)
		return;
	for(int i=0;i<(n-l+1);i++)
	{
		for(int j=i+1;j<(n-l+1);j++)
		{
			int c=0;
			for(int dl=0;dl<l;dl++)
			{
				c+=(hp[i][dl]!=hp[j][dl]);
			}
			ans[i][c]++;
			ans[j][c]++;
		}
	}
	posa=1;
}
struct Node{
	Node *child[N];
	int cnt1=0;
};
Node* root=new Node();
void insert(vector<int>& a)
{
	Node* cur=root;
	for(int i=0;i<l;i++)
	{
		if(cur->child[a[i]]==NULL)
			cur->child[a[i]]=new Node();
		cur=cur->child[a[i]];
		cur->cnt1++;
	}
}
int query(vector<int>& a)
{
	Node* cur=root;
	for(int i=0;i<l;i++)
		cur=cur->child[a[i]];
	return cur->cnt1-1;
}
int main()
{
	cin>>n>>l;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];		
		cpy[i]=a[i];
	}
	sort(cpy,cpy+n);
	for(int i=0;i<n;i++)
		a[i]=lower_bound(cpy,cpy+n,a[i])-cpy;
	int q;
	cin>>q;
	if(q==-1)
	{
		int k;
		cin>>k;
		if(k==0)
		{
			// using Trie;
			for(int i=0;(i+l-1)<n;i++)
			{
				vector<int> ap;
				for(int j=0;j<l;j++)
					ap.push_back(a[i+j]);
				insert(ap);
			}
			for(int i=0;(i+l-1)<n;i++)
			{
				vector<int> ap;
				for(int j=0;j<l;j++)
					ap.push_back(a[i+j]);
				cout<<query(ap)<<' ';
			}
			cout<<'\n';
		}
		else
		{
			for(int i=0;(i+l-1)<n;i++)
			{
				vector<int> ap;
				for(int j=0;j<l;j++)
					ap.push_back(a[i+j]);
				hp.push_back(ap);
			}
			level_up();
			for(int i=0;(i+l-1)<n;i++)
			{
				int sp=0;
				for(int lp=0;lp<=k;lp++)
					if(ans[i].find(lp)!=ans[i].end())
						sp+=ans[i][lp];
				cout<<sp<<' ';
			}
			cout<<'\n';
		}
	}
	else
	{
		for(int i=0;(i+l-1)<n;i++)
		{
			vector<int> ap;
			for(int j=0;j<l;j++)
				ap.push_back(a[i+j]);
			hp.push_back(ap);
		}
		level_up();
		while(q--)
		{
			int k;
			cin>>k;
			for(int i=0;(i+l-1)<n;i++)
			{
				int sp=0;
				for(int lp=0;lp<=k;lp++)
					if(ans[i].find(lp)!=ans[i].end())
						sp+=ans[i][lp];
				cout<<sp<<' ';
			}
			cout<<'\n';
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 4 ms 1312 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 1112 KB Output is correct
11 Correct 2 ms 856 KB Output is correct
12 Correct 3 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 4 ms 1312 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 1112 KB Output is correct
11 Correct 2 ms 856 KB Output is correct
12 Correct 3 ms 1112 KB Output is correct
13 Correct 30 ms 1484 KB Output is correct
14 Correct 475 ms 4688 KB Output is correct
15 Correct 466 ms 4944 KB Output is correct
16 Correct 324 ms 5200 KB Output is correct
17 Correct 363 ms 3316 KB Output is correct
18 Correct 357 ms 4120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 738 ms 3480 KB Output is correct
2 Correct 1079 ms 4884 KB Output is correct
3 Correct 597 ms 3468 KB Output is correct
4 Execution timed out 3014 ms 10780 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 738 ms 3480 KB Output is correct
2 Correct 1079 ms 4884 KB Output is correct
3 Correct 597 ms 3468 KB Output is correct
4 Execution timed out 3014 ms 10780 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 4 ms 1312 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 1112 KB Output is correct
11 Correct 2 ms 856 KB Output is correct
12 Correct 3 ms 1112 KB Output is correct
13 Correct 30 ms 1484 KB Output is correct
14 Correct 475 ms 4688 KB Output is correct
15 Correct 466 ms 4944 KB Output is correct
16 Correct 324 ms 5200 KB Output is correct
17 Correct 363 ms 3316 KB Output is correct
18 Correct 357 ms 4120 KB Output is correct
19 Correct 738 ms 3480 KB Output is correct
20 Correct 1079 ms 4884 KB Output is correct
21 Correct 597 ms 3468 KB Output is correct
22 Execution timed out 3014 ms 10780 KB Time limit exceeded
23 Halted 0 ms 0 KB -