Submission #683844

# Submission time Handle Problem Language Result Execution time Memory
683844 2023-01-19T13:20:25 Z abc864197532 Monochrome Points (JOI20_monochrome) C++17
0 / 100
1 ms 308 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;
	int m = W.size();
	vector <int> dp(1 << m, 1 << 30);
	dp[0] = 0;
	for (int s = 0; s < (1 << m); ++s) {
		int num = __builtin_popcount(s);
		for (int i = 0; i < m; ++i) if (~s >> i & 1) {
			dp[s | (1 << i)] = min(dp[s | (1 << i)], dp[s] + abs(W[i] - B[num]));
		}
	}
	cout << ans - dp.back() << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 1 ms 308 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 1 ms 308 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 1 ms 308 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 1 ms 308 KB Output isn't correct
6 Halted 0 ms 0 KB -