답안 #548726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548726 2022-04-14T10:48:36 Z usukhbaatar Collecting Mushrooms (NOI18_collectmushrooms) C++14
60 / 100
73 ms 14812 KB
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int H, W, D, K;
vector<pair<pair<int, int>, pair<int, int>>> v;

int bit[1000001];

int N;

int query(int i) {
	int ii = i;
	int res = 0;
	while (i > 0) {
		res += bit[i];
		i -= (i & -i);
	}
	//cout << "query: " << ii << ": " << res << endl;
	return res;
}

void update(int i, int x) {
	while (i <= N) {
		bit[i] += x;
		i += (i & -i);
	}
}

void update(int l, int r, int x) {
	//cout << "update: " << l << " " << r << " " << x << endl;
	update(l, x);
	update(r + 1, -x);
}

int main() {
	cin >> H >> W >> D >> K;
	N = W + 2 * D;
	string temp;

	for (int i = 0; i < H; i++) {
		cin >> temp;
		for (int j = 0; j < W; j++) {
			if (temp[j] == 'M') {
				v.push_back({{i, 2}, {j + D + 1, j + D + 1}});
			}
			if (temp[j] == 'S') {
				v.push_back({{i - D, 1}, {j + 1, j + 2 * D + 1}});
				v.push_back({{i + D, 3}, {j + 1, j + 2 * D + 1}});
			}
		}
	}

	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].first.second == 2) {
			int temp = query(v[i].second.first);
			//cout << temp << endl;
			if (temp >= K) {
				ans++;
			}
		} else {
			update(v[i].second.first, v[i].second.second, v[i].first.second == 3 ? -1 : 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Compilation message

mushrooms.cpp: In function 'int query(int)':
mushrooms.cpp:15:6: warning: unused variable 'ii' [-Wunused-variable]
   15 |  int ii = i;
      |      ^~
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 5 ms 496 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 10488 KB Output is correct
2 Correct 73 ms 10444 KB Output is correct
3 Runtime error 61 ms 14812 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 5 ms 496 KB Output is correct
20 Correct 6 ms 340 KB Output is correct
21 Correct 64 ms 10488 KB Output is correct
22 Correct 73 ms 10444 KB Output is correct
23 Runtime error 61 ms 14812 KB Execution killed with signal 11
24 Halted 0 ms 0 KB -