답안 #259924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259924 2020-08-08T19:52:08 Z pedroslrey Lottery (CEOI18_lot) C++17
100 / 100
1688 ms 8512 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e4 + 10;
const int MAXQ = 1e2 + 10;

int xs[MAXN];
int ans[MAXQ][MAXN];
int rev[MAXQ];
vector<pair<int, int>> queries;

void calc(int n, int l) {
	for (int space = 1; space + l - 1 < n; ++space) {
		int diffs = 0;
		for (int i = 0; i < l; ++i)
		if (xs[i] != xs[i + space])
				++diffs;

		int idx = lower_bound(queries.begin(), queries.end(), make_pair(diffs, 0)) - queries.begin();
		++ans[idx][0];
		++ans[idx][space];

		for (int i = 1; i + space + l - 1 < n; ++i) {
			if (xs[i-1] != xs[i + space - 1])
				--diffs;
	
			if (xs[i + l - 1] != xs[i + l + space - 1])
				++diffs;
	
			int idx = lower_bound(queries.begin(), queries.end(), make_pair(diffs, 0)) - queries.begin();
			++ans[idx][i];
			++ans[idx][i + space];
		}
	}
}

int main() {
	int n, l;
	scanf("%d%d", &n, &l);

	for (int i = 0; i < n; ++i)
		scanf("%d", &xs[i]);

	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int k;
		scanf("%d", &k);

		queries.push_back({k, i});
	}

	sort(queries.begin(), queries.end());

	calc(n, l);

	for (int i = 0; i < q; ++i)
		rev[queries[i].second] = i;

	for (int i = 1; i < q; ++i)
		for (int j = 0; j < n - l + 1; ++j)
			ans[i][j] += ans[i-1][j];

	for (int i = 0; i < q; ++i) {
		for (int j = 0; j < n - l + 1; ++j)
			printf("%d ", ans[rev[i]][j]);
		printf("\n");
	}
}

Compilation message

lot.cpp: In function 'int main()':
lot.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &l);
  ~~~~~^~~~~~~~~~~~~~~~
lot.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &xs[i]);
   ~~~~~^~~~~~~~~~~~~~
lot.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
lot.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k);
   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 26 ms 436 KB Output is correct
14 Correct 14 ms 512 KB Output is correct
15 Correct 13 ms 512 KB Output is correct
16 Correct 25 ms 632 KB Output is correct
17 Correct 22 ms 572 KB Output is correct
18 Correct 22 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 654 ms 484 KB Output is correct
2 Correct 690 ms 504 KB Output is correct
3 Correct 485 ms 480 KB Output is correct
4 Correct 426 ms 504 KB Output is correct
5 Correct 131 ms 508 KB Output is correct
6 Correct 382 ms 508 KB Output is correct
7 Correct 115 ms 384 KB Output is correct
8 Correct 202 ms 504 KB Output is correct
9 Correct 408 ms 480 KB Output is correct
10 Correct 421 ms 504 KB Output is correct
11 Correct 25 ms 384 KB Output is correct
12 Correct 257 ms 436 KB Output is correct
13 Correct 184 ms 504 KB Output is correct
14 Correct 192 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 654 ms 484 KB Output is correct
2 Correct 690 ms 504 KB Output is correct
3 Correct 485 ms 480 KB Output is correct
4 Correct 426 ms 504 KB Output is correct
5 Correct 131 ms 508 KB Output is correct
6 Correct 382 ms 508 KB Output is correct
7 Correct 115 ms 384 KB Output is correct
8 Correct 202 ms 504 KB Output is correct
9 Correct 408 ms 480 KB Output is correct
10 Correct 421 ms 504 KB Output is correct
11 Correct 25 ms 384 KB Output is correct
12 Correct 257 ms 436 KB Output is correct
13 Correct 184 ms 504 KB Output is correct
14 Correct 192 ms 384 KB Output is correct
15 Correct 462 ms 504 KB Output is correct
16 Correct 363 ms 384 KB Output is correct
17 Correct 468 ms 508 KB Output is correct
18 Correct 461 ms 460 KB Output is correct
19 Correct 433 ms 488 KB Output is correct
20 Correct 432 ms 384 KB Output is correct
21 Correct 435 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 26 ms 436 KB Output is correct
14 Correct 14 ms 512 KB Output is correct
15 Correct 13 ms 512 KB Output is correct
16 Correct 25 ms 632 KB Output is correct
17 Correct 22 ms 572 KB Output is correct
18 Correct 22 ms 640 KB Output is correct
19 Correct 654 ms 484 KB Output is correct
20 Correct 690 ms 504 KB Output is correct
21 Correct 485 ms 480 KB Output is correct
22 Correct 426 ms 504 KB Output is correct
23 Correct 131 ms 508 KB Output is correct
24 Correct 382 ms 508 KB Output is correct
25 Correct 115 ms 384 KB Output is correct
26 Correct 202 ms 504 KB Output is correct
27 Correct 408 ms 480 KB Output is correct
28 Correct 421 ms 504 KB Output is correct
29 Correct 25 ms 384 KB Output is correct
30 Correct 257 ms 436 KB Output is correct
31 Correct 184 ms 504 KB Output is correct
32 Correct 192 ms 384 KB Output is correct
33 Correct 462 ms 504 KB Output is correct
34 Correct 363 ms 384 KB Output is correct
35 Correct 468 ms 508 KB Output is correct
36 Correct 461 ms 460 KB Output is correct
37 Correct 433 ms 488 KB Output is correct
38 Correct 432 ms 384 KB Output is correct
39 Correct 435 ms 504 KB Output is correct
40 Correct 1258 ms 1916 KB Output is correct
41 Correct 20 ms 640 KB Output is correct
42 Correct 654 ms 2040 KB Output is correct
43 Correct 603 ms 1784 KB Output is correct
44 Correct 598 ms 1784 KB Output is correct
45 Correct 1688 ms 8312 KB Output is correct
46 Correct 26 ms 1528 KB Output is correct
47 Correct 880 ms 8512 KB Output is correct
48 Correct 786 ms 6648 KB Output is correct
49 Correct 790 ms 7288 KB Output is correct