답안 #411574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411574 2021-05-25T14:12:28 Z nichke Monochrome Points (JOI20_monochrome) C++14
35 / 100
2000 ms 14724 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

int ans;
int n;
string s;

vector<int> a, b;
int bit[400005];

void clr() {
	for (int i = 1; i <= 2 * n; i++) {
		bit[i] = 0;
	}
}

void upd(int v, int k) {
	while (v <= 2 * n) {
		bit[v] += k;
		v += (v & (-v));
	}
}

int qry(int v) {
	int res = 0;
	while (v) {
		res += bit[v];
		v -= (v & (-v));
	}
	return res;
}

int sum(int l, int r) {
	return qry(r) - qry(l - 1);
}

int calc(int k) {
	int res = 0;
	vector<pair<int, int>> v;
	for (int i = 0; i < n; i++) {
		v.push_back({a[i], b[(i + k) % n]});
	}
	for (int i = 0; i < v.size(); i++) {
		if (v[i].first > v[i].second) {
			swap(v[i].first, v[i].second);
		}
	}
	sort(v.begin(), v.end());
	clr();
	for (int i = 0; i < v.size(); i++) {
		res += sum(v[i].first, v[i].second);
		upd(v[i].second, 1);
	}
	return res;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> s;
	for (int i = 0; i < 2 * n; i++) {
		if (s[i] == 'W') {
			a.push_back(i + 1);
		} else {
			b.push_back(i + 1);
		}
	}
	for (int i = 0; i < n; i++) {
		ans = max(ans, calc(i));
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

monochrome.cpp: In function 'long long int calc(long long int)':
monochrome.cpp:45:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
monochrome.cpp:52:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 7 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 7 ms 332 KB Output is correct
17 Correct 7 ms 332 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 6 ms 316 KB Output is correct
20 Correct 6 ms 332 KB Output is correct
21 Correct 5 ms 356 KB Output is correct
22 Correct 6 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 6 ms 332 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 7 ms 332 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 7 ms 332 KB Output is correct
31 Correct 8 ms 352 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 7 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 7 ms 332 KB Output is correct
17 Correct 7 ms 332 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 6 ms 316 KB Output is correct
20 Correct 6 ms 332 KB Output is correct
21 Correct 5 ms 356 KB Output is correct
22 Correct 6 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 6 ms 332 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 7 ms 332 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 7 ms 332 KB Output is correct
31 Correct 8 ms 352 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
34 Correct 319 ms 460 KB Output is correct
35 Correct 315 ms 440 KB Output is correct
36 Correct 318 ms 452 KB Output is correct
37 Correct 292 ms 460 KB Output is correct
38 Correct 266 ms 452 KB Output is correct
39 Correct 271 ms 432 KB Output is correct
40 Correct 236 ms 460 KB Output is correct
41 Correct 219 ms 332 KB Output is correct
42 Correct 302 ms 440 KB Output is correct
43 Correct 267 ms 436 KB Output is correct
44 Correct 285 ms 460 KB Output is correct
45 Correct 283 ms 432 KB Output is correct
46 Correct 307 ms 432 KB Output is correct
47 Correct 251 ms 332 KB Output is correct
48 Correct 259 ms 460 KB Output is correct
49 Correct 226 ms 440 KB Output is correct
50 Correct 284 ms 432 KB Output is correct
51 Correct 254 ms 440 KB Output is correct
52 Correct 317 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 7 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 7 ms 332 KB Output is correct
17 Correct 7 ms 332 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 6 ms 316 KB Output is correct
20 Correct 6 ms 332 KB Output is correct
21 Correct 5 ms 356 KB Output is correct
22 Correct 6 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 6 ms 332 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 7 ms 332 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 7 ms 332 KB Output is correct
31 Correct 8 ms 352 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
34 Correct 319 ms 460 KB Output is correct
35 Correct 315 ms 440 KB Output is correct
36 Correct 318 ms 452 KB Output is correct
37 Correct 292 ms 460 KB Output is correct
38 Correct 266 ms 452 KB Output is correct
39 Correct 271 ms 432 KB Output is correct
40 Correct 236 ms 460 KB Output is correct
41 Correct 219 ms 332 KB Output is correct
42 Correct 302 ms 440 KB Output is correct
43 Correct 267 ms 436 KB Output is correct
44 Correct 285 ms 460 KB Output is correct
45 Correct 283 ms 432 KB Output is correct
46 Correct 307 ms 432 KB Output is correct
47 Correct 251 ms 332 KB Output is correct
48 Correct 259 ms 460 KB Output is correct
49 Correct 226 ms 440 KB Output is correct
50 Correct 284 ms 432 KB Output is correct
51 Correct 254 ms 440 KB Output is correct
52 Correct 317 ms 440 KB Output is correct
53 Execution timed out 2074 ms 14724 KB Time limit exceeded
54 Halted 0 ms 0 KB -