답안 #683843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683843 2023-01-19T13:13:41 Z abc864197532 Monochrome Points (JOI20_monochrome) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(), x.end()

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	vector <int> W, B;
	for (int i = 0; i < n; ++i) {
		if (s[i] == s[i + n]) {
			(s[i] == 'W' ? W : B).pb(i);
		}
	}
	ll ans = 1ll * n * (n - 1) / 2, mn = 1ll << 60;
	int m = W.size();
	if (!m) {
		cout << ans << '\n';
		return 0;
	}
	for (int rt = 0; rt < m; ++rt) {
		ll sum = 0;
		for (int i = 0; i < m; ++i) {
			int len = abs(W[i] - B[(i + rt) % m]);
			sum += min(len, 2 * n - len);
		}
		mn = min(mn, sum);
	}
	cout << ans - mn << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -