Submission #412371

# Submission time Handle Problem Language Result Execution time Memory
412371 2021-05-26T18:08:43 Z nichke Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
9000 ms 1708 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
	vector<int> cnt((int)A.size());
	vector<int> ans;
	for (int i = 0; i < A.size(); i++) {
		for (int j = 0; j < i; j++) {
			if (A[j] > A[i]) {
				cnt[i]++;
			}
		}
	}
	for (int i = 0; i < X.size(); i++) {
		int tmp = A[X[i]];
		A[X[i]] = V[i];
		int res = 0;
		for (int j = X[i] + 1; j < A.size(); j++) {
			if (tmp > A[j] && A[X[i]] > A[j]) continue;
			if (tmp <= A[j] && A[X[i]] <= A[j]) continue;
			if (tmp > A[j] && A[X[i]] <= A[j]) cnt[j]--;
			if (tmp <= A[j] && A[X[i]] > A[j]) cnt[j]++;
		}
		cnt[X[i]] = 0;
		for (int j = X[i] - 1; j >= 0; j--) {
			if (A[j] > A[X[i]]) {
				cnt[X[i]]++;
			}
		}
		for (int j = 0; j < A.size(); j++) {
			res = max(res, cnt[j]);
		}
		ans.push_back(res);
	}
	return ans;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:7:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  for (int i = 0; i < A.size(); i++) {
      |                  ~~^~~~~~~~~~
bubblesort2.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 0; i < X.size(); i++) {
      |                  ~~^~~~~~~~~~
bubblesort2.cpp:18:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for (int j = X[i] + 1; j < A.size(); j++) {
      |                          ~~^~~~~~~~~~
bubblesort2.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for (int j = 0; j < A.size(); j++) {
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 204 KB Output is correct
2 Correct 7 ms 316 KB Output is correct
3 Correct 35 ms 356 KB Output is correct
4 Correct 34 ms 332 KB Output is correct
5 Correct 27 ms 364 KB Output is correct
6 Correct 18 ms 360 KB Output is correct
7 Correct 22 ms 332 KB Output is correct
8 Correct 24 ms 332 KB Output is correct
9 Correct 28 ms 332 KB Output is correct
10 Correct 23 ms 332 KB Output is correct
11 Correct 25 ms 332 KB Output is correct
12 Correct 24 ms 344 KB Output is correct
13 Correct 23 ms 348 KB Output is correct
14 Correct 23 ms 332 KB Output is correct
15 Correct 23 ms 356 KB Output is correct
16 Correct 22 ms 344 KB Output is correct
17 Correct 22 ms 356 KB Output is correct
18 Correct 22 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 204 KB Output is correct
2 Correct 7 ms 316 KB Output is correct
3 Correct 35 ms 356 KB Output is correct
4 Correct 34 ms 332 KB Output is correct
5 Correct 27 ms 364 KB Output is correct
6 Correct 18 ms 360 KB Output is correct
7 Correct 22 ms 332 KB Output is correct
8 Correct 24 ms 332 KB Output is correct
9 Correct 28 ms 332 KB Output is correct
10 Correct 23 ms 332 KB Output is correct
11 Correct 25 ms 332 KB Output is correct
12 Correct 24 ms 344 KB Output is correct
13 Correct 23 ms 348 KB Output is correct
14 Correct 23 ms 332 KB Output is correct
15 Correct 23 ms 356 KB Output is correct
16 Correct 22 ms 344 KB Output is correct
17 Correct 22 ms 356 KB Output is correct
18 Correct 22 ms 340 KB Output is correct
19 Correct 434 ms 588 KB Output is correct
20 Correct 534 ms 684 KB Output is correct
21 Correct 347 ms 688 KB Output is correct
22 Correct 441 ms 684 KB Output is correct
23 Correct 352 ms 744 KB Output is correct
24 Correct 352 ms 652 KB Output is correct
25 Correct 352 ms 688 KB Output is correct
26 Correct 345 ms 660 KB Output is correct
27 Correct 345 ms 672 KB Output is correct
28 Correct 339 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1855 ms 620 KB Output is correct
2 Execution timed out 9066 ms 1708 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 204 KB Output is correct
2 Correct 7 ms 316 KB Output is correct
3 Correct 35 ms 356 KB Output is correct
4 Correct 34 ms 332 KB Output is correct
5 Correct 27 ms 364 KB Output is correct
6 Correct 18 ms 360 KB Output is correct
7 Correct 22 ms 332 KB Output is correct
8 Correct 24 ms 332 KB Output is correct
9 Correct 28 ms 332 KB Output is correct
10 Correct 23 ms 332 KB Output is correct
11 Correct 25 ms 332 KB Output is correct
12 Correct 24 ms 344 KB Output is correct
13 Correct 23 ms 348 KB Output is correct
14 Correct 23 ms 332 KB Output is correct
15 Correct 23 ms 356 KB Output is correct
16 Correct 22 ms 344 KB Output is correct
17 Correct 22 ms 356 KB Output is correct
18 Correct 22 ms 340 KB Output is correct
19 Correct 434 ms 588 KB Output is correct
20 Correct 534 ms 684 KB Output is correct
21 Correct 347 ms 688 KB Output is correct
22 Correct 441 ms 684 KB Output is correct
23 Correct 352 ms 744 KB Output is correct
24 Correct 352 ms 652 KB Output is correct
25 Correct 352 ms 688 KB Output is correct
26 Correct 345 ms 660 KB Output is correct
27 Correct 345 ms 672 KB Output is correct
28 Correct 339 ms 700 KB Output is correct
29 Correct 1855 ms 620 KB Output is correct
30 Execution timed out 9066 ms 1708 KB Time limit exceeded
31 Halted 0 ms 0 KB -