답안 #977459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977459 2024-05-08T02:37:49 Z shoryu386 Money (IZhO17_money) C++17
100 / 100
156 ms 21728 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MX 1000007
int fwt[MX+1];
#define lsb(x) (x&(-x))

void update(int x, int k){
	x++;
	
	for (; x < MX; x += lsb(x)){
		fwt[x] += k;
	}
}

int sum(int x){
	x++;
	
	int res = 0;
	for (; x != 0; x -= lsb(x)){
		res += fwt[x];
	}
	
	return res;
}

int query(int a, int b){
	if (b < a) return 0;
	return sum(b) - sum(a-1);
}

main(){ ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin >> n;
	//attempt greedy
	
	int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x];
	
	bitset<1000007> taken;
	int ans = 0;
	for (int zzz = 0; zzz < n; zzz++){
		if (taken[zzz]){
			continue;
		}
		
		ans++;
		
		taken[zzz] = 1;
		vector<int> items; items.push_back(arr[zzz]);
		
		for (int y = zzz+1; y < n; y++){
			if (items.back() <= arr[y] && query(arr[zzz]+1, arr[y]-1) == 0){
				taken[y] = 1;
				items.push_back(arr[y]);
			}
			else{
				break;
			}
		}
		
		for (auto y : items){
			update(y, 1);
		}
		
	}
	
	cout << ans;
	
	
}

Compilation message

money.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){ ios_base::sync_with_stdio(0); cin.tie(0);
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 2848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 2848 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 2848 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 860 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 0 ms 604 KB Output is correct
37 Correct 1 ms 3932 KB Output is correct
38 Correct 1 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 2848 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 860 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 0 ms 604 KB Output is correct
37 Correct 1 ms 3932 KB Output is correct
38 Correct 1 ms 3932 KB Output is correct
39 Correct 58 ms 6228 KB Output is correct
40 Correct 90 ms 15192 KB Output is correct
41 Correct 44 ms 10056 KB Output is correct
42 Correct 41 ms 5832 KB Output is correct
43 Correct 28 ms 4188 KB Output is correct
44 Correct 113 ms 13892 KB Output is correct
45 Correct 112 ms 13664 KB Output is correct
46 Correct 116 ms 13908 KB Output is correct
47 Correct 105 ms 13576 KB Output is correct
48 Correct 111 ms 15868 KB Output is correct
49 Correct 120 ms 21336 KB Output is correct
50 Correct 126 ms 21520 KB Output is correct
51 Correct 122 ms 21588 KB Output is correct
52 Correct 128 ms 21332 KB Output is correct
53 Correct 120 ms 21412 KB Output is correct
54 Correct 129 ms 21360 KB Output is correct
55 Correct 134 ms 21420 KB Output is correct
56 Correct 129 ms 21468 KB Output is correct
57 Correct 156 ms 21728 KB Output is correct
58 Correct 127 ms 21576 KB Output is correct
59 Correct 129 ms 21580 KB Output is correct
60 Correct 130 ms 21416 KB Output is correct
61 Correct 129 ms 21508 KB Output is correct
62 Correct 130 ms 21584 KB Output is correct