답안 #70965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70965 2018-08-23T21:11:42 Z MatheusLealV Lottery (CEOI18_lot) C++17
100 / 100
1800 ms 9788 KB
#include <bits/stdc++.h>
#define N 10030
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

pii q[N];

int n, dx, qq, v[N], c, zero[N], k[N], nxt[2*N], id[150];

int pref[N][130];

bool out(int i, int j)
{
	int l = i + dx - 1;

	int r = j + dx - 1;

	if(l > n or r > n or j < 1 or j <= i) return true;;

	return false;
}

inline void solveD(int fl, vector<int>& vet)
{
	int i = 1, j = fl, id;

	c = i - j;

	vet[0] = 0, id = 1;

	while(i <= n and j <= n)
	{
		vet[id] = vet[id - 1] + (v[i] != v[j]);
		
		i ++, j ++, id ++;
	}

	for(int i = 1; i <= n and i != j; i++)
	{
		int l = i + dx - 1, j = i - c;

		if(out(i, j)) continue;

		int dif = vet[l] - vet[i - 1];

		int p = nxt[dif];

		pref[i][p] ++;

		pref[j][p] ++;
	}
}

inline void solveE(int fl, vector<int>& vet)
{
	int i = fl, j = 1;

	int c = i - j, id = 1;

	vet[0] = 0;

	while(i <= n and j <= n)
	{
		vet[id] = vet[id - 1] + (v[i] != v[j]);

		i ++, j ++, id ++;
	}

	for(int i = 1; i <= n; i++)
	{
		int j = i - c;

		int r = j + dx - 1;

		if(out(i, j)) continue;

		int dif = vet[r] - vet[j - 1];

		int p = nxt[dif];

		pref[i][p] ++;

		pref[j][p] ++;
	}
}

inline void init()
{
	sort(q + 1, q + qq + 1);

	for(int i = 1; i <= qq; i++) id[q[i].s] = i;

	for(int i = 0; i < 20060; i++)
	{
		nxt[i] = 110;

		for(int j = 1; j <= qq ; j++)
		{
			if(q[j].f >= i)
			{
				nxt[i] = j;

				break;
			}
		}
	}
}


int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>dx;

	for(int i = 1; i <= n; i++) cin>>v[i];

	cin>>qq;

	for(int i = 1, k; i <= qq; i++) cin>>k, q[i] = {k, i};

	init();

	for(int fl = 1; fl <= n; fl ++)
	{
		vector<int> vet(2*n);

		solveE(fl, vet);

		if(fl > 1) solveD(fl, vet);
	}

	for(int i = 1; i <= qq; i++)
	{
		if(i == 1)
		{
			for(int t = 0; t < 130; t++)
				for(int j = 1; j <= n; j++) pref[j][t] += pref[j][t - 1];
		}

		for(int j = 1; j <= n - dx + 1; j++) cout<<pref[j][id[i]]<<" ";

		cout<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 672 KB Output is correct
8 Correct 5 ms 876 KB Output is correct
9 Correct 4 ms 892 KB Output is correct
10 Correct 5 ms 892 KB Output is correct
11 Correct 5 ms 908 KB Output is correct
12 Correct 4 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 672 KB Output is correct
8 Correct 5 ms 876 KB Output is correct
9 Correct 4 ms 892 KB Output is correct
10 Correct 5 ms 892 KB Output is correct
11 Correct 5 ms 908 KB Output is correct
12 Correct 4 ms 924 KB Output is correct
13 Correct 65 ms 1820 KB Output is correct
14 Correct 60 ms 1820 KB Output is correct
15 Correct 58 ms 1840 KB Output is correct
16 Correct 63 ms 1840 KB Output is correct
17 Correct 62 ms 1840 KB Output is correct
18 Correct 58 ms 1840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1728 ms 6060 KB Output is correct
2 Correct 1580 ms 6060 KB Output is correct
3 Correct 1713 ms 6060 KB Output is correct
4 Correct 1633 ms 6060 KB Output is correct
5 Correct 1293 ms 6060 KB Output is correct
6 Correct 1563 ms 6060 KB Output is correct
7 Correct 1182 ms 6060 KB Output is correct
8 Correct 1512 ms 6112 KB Output is correct
9 Correct 1580 ms 6188 KB Output is correct
10 Correct 1652 ms 6188 KB Output is correct
11 Correct 117 ms 6188 KB Output is correct
12 Correct 1141 ms 6188 KB Output is correct
13 Correct 1345 ms 6188 KB Output is correct
14 Correct 1222 ms 6188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1728 ms 6060 KB Output is correct
2 Correct 1580 ms 6060 KB Output is correct
3 Correct 1713 ms 6060 KB Output is correct
4 Correct 1633 ms 6060 KB Output is correct
5 Correct 1293 ms 6060 KB Output is correct
6 Correct 1563 ms 6060 KB Output is correct
7 Correct 1182 ms 6060 KB Output is correct
8 Correct 1512 ms 6112 KB Output is correct
9 Correct 1580 ms 6188 KB Output is correct
10 Correct 1652 ms 6188 KB Output is correct
11 Correct 117 ms 6188 KB Output is correct
12 Correct 1141 ms 6188 KB Output is correct
13 Correct 1345 ms 6188 KB Output is correct
14 Correct 1222 ms 6188 KB Output is correct
15 Correct 1550 ms 6188 KB Output is correct
16 Correct 1443 ms 6188 KB Output is correct
17 Correct 1572 ms 6188 KB Output is correct
18 Correct 1615 ms 6188 KB Output is correct
19 Correct 1714 ms 6188 KB Output is correct
20 Correct 1684 ms 6188 KB Output is correct
21 Correct 1696 ms 6188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 672 KB Output is correct
8 Correct 5 ms 876 KB Output is correct
9 Correct 4 ms 892 KB Output is correct
10 Correct 5 ms 892 KB Output is correct
11 Correct 5 ms 908 KB Output is correct
12 Correct 4 ms 924 KB Output is correct
13 Correct 65 ms 1820 KB Output is correct
14 Correct 60 ms 1820 KB Output is correct
15 Correct 58 ms 1840 KB Output is correct
16 Correct 63 ms 1840 KB Output is correct
17 Correct 62 ms 1840 KB Output is correct
18 Correct 58 ms 1840 KB Output is correct
19 Correct 1728 ms 6060 KB Output is correct
20 Correct 1580 ms 6060 KB Output is correct
21 Correct 1713 ms 6060 KB Output is correct
22 Correct 1633 ms 6060 KB Output is correct
23 Correct 1293 ms 6060 KB Output is correct
24 Correct 1563 ms 6060 KB Output is correct
25 Correct 1182 ms 6060 KB Output is correct
26 Correct 1512 ms 6112 KB Output is correct
27 Correct 1580 ms 6188 KB Output is correct
28 Correct 1652 ms 6188 KB Output is correct
29 Correct 117 ms 6188 KB Output is correct
30 Correct 1141 ms 6188 KB Output is correct
31 Correct 1345 ms 6188 KB Output is correct
32 Correct 1222 ms 6188 KB Output is correct
33 Correct 1550 ms 6188 KB Output is correct
34 Correct 1443 ms 6188 KB Output is correct
35 Correct 1572 ms 6188 KB Output is correct
36 Correct 1615 ms 6188 KB Output is correct
37 Correct 1714 ms 6188 KB Output is correct
38 Correct 1684 ms 6188 KB Output is correct
39 Correct 1696 ms 6188 KB Output is correct
40 Correct 1730 ms 6844 KB Output is correct
41 Correct 1137 ms 6844 KB Output is correct
42 Correct 1742 ms 6844 KB Output is correct
43 Correct 1588 ms 6844 KB Output is correct
44 Correct 1516 ms 6844 KB Output is correct
45 Correct 1737 ms 9788 KB Output is correct
46 Correct 1104 ms 9788 KB Output is correct
47 Correct 1800 ms 9788 KB Output is correct
48 Correct 1632 ms 9788 KB Output is correct
49 Correct 1742 ms 9788 KB Output is correct