# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
293120 | Berted | Monochrome Points (JOI20_monochrome) | C++14 | 68 ms | 1944 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
int n; string s;
vector<int> C[2];
long long ans = 0;
bool matchWith[100001];
long long solve(int x)
{
long long temp = 0;
for (int i = 0; i < C[0].size(); i++)
{
temp += min(abs(C[1][(i + x) % C[1].size()] - C[0][i]), n - abs(C[1][(i + x) % C[1].size()] - C[0][i]));
}
return temp;
}
long long binser(int L, int R)
{
while (L < R)
{
int M = L + R >> 1;
if (solve(M) < solve(M + 1)) {R = M;}
else {L = M + 1;}
}
long long ret = 1e18;
for (int i = max(0, L - 5); i < min(L + 5, (int)C[0].size()); i++) {ret = min(ret, solve(i));}
return ret;
}
int main()
{
cin >> n >> s;
for (int i = 0; i < n; i++)
{
if (s[i] == s[i + n]) {C[s[i] == 'W'].push_back(i);}
}
ans = (long long)n * (n - 1) / 2;
if (C[0].size())
{
long long res = 1e18;
res = min(binser(0, (int)C[0].size() / 2 - 1), binser((int)C[0].size() / 2, (int)C[0].size() - 2));
ans -= res;
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |