# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1000325 | MateiKing80 | Monochrome Points (JOI20_monochrome) | C++14 | 1 ms | 436 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
string s;
vector<int> w, b;
#define lsb(x) (x & -x)
struct AIB
{
vector<int> tree;
AIB(int n)
{
tree.assign(n + 5, 0);
}
void upd(int p, int x)
{
while(p < tree.size())
tree[p] += x, p += lsb(p);
}
int query(int p)
{
int sum = 0;
while(p > 0)
sum += tree[p], p -= lsb(p);
return sum;
}
};
int n;
int nrInv(int k)
{
int ans = 0;
AIB ds(2 * n);
vector<pair<int, int>> v;
for(int i = 0; i < n; i ++)
v.push_back({w[i], b[(i + k) % n]});
for(auto &i : v)
if(i.first > i.second)
swap(i.first, i.second);
sort(v.begin(), v.end());
for(int i = 0; i < n; i ++)
{
//cout << v[i].first << " " << v[i].second << "\n";
ans += ds.query(v[i].second) - ds.query(v[i].first);
ds.upd(v[i].second, 1);
}
//cout << '\n';
return ans;
}
signed main()
{
cin >> n >> s;
for(int i = 0; i < 2 * n; i ++)
{
if(s[i] == 'B')
b.push_back(i + 1);
else
w.push_back(i + 1);
}
int pas = (1 << 20), pos = 0;
while(pas)
{
if(pos + pas < n && nrInv(pos + pas - 1) < nrInv(pos + pas))
pos += pas;
pas /= 2;
}
cout << nrInv(pos);
}
컴파일 시 표준 에러 (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... |