# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334361 | CodeTiger927 | ČVENK (COI15_cvenk) | C++14 | 3061 ms | 93932 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
using namespace std;
#include <iostream>
#define MAXN 100005
struct node {
node* c[2];
int x,y,s,xy;
node(int _x,int _y): x(_x),y(_y),xy(_x + _y),s(0) {
c[0] = c[1] = nullptr;
}
node* insert(node* next,bool lr) {
s++;
if(!c[lr]) c[lr] = next;
if(next -> x < c[lr] -> x || next -> y < c[lr] -> y) {
next -> c[lr] = c[lr];
next -> s += c[lr] -> s;
c[lr] = next;
return next;
}
if(next -> x > c[lr] -> x || next -> y > c[lr] -> y) {
return c[lr] -> insert(next,lr);
}
return c[lr];
}
};
node* root = new node(0,0);
long long sum,ans;
int N,qx[MAXN],qy[MAXN];
void dfs(node* cur,long long curN) {
ans = min(ans,curN);
if(cur -> c[0]) dfs(cur -> c[0],curN + (1ll * N - 2 * cur -> c[0] -> s) * (cur -> c[0] -> xy - cur -> xy));
if(cur -> c[1]) dfs(cur -> c[1],curN + (1ll * N - 2 * cur -> c[1] -> s) * (cur -> c[1] -> xy - cur -> xy));
}
int main() {
cin >> N;
for(int i = 0;i < N;++i) {
cin >> qx[i] >> qy[i];
sum += qx[i] + qy[i];
int curX,curY;
curX = curY = 0;
node* cur = root;
for(int j = 29;j >= 0;--j) {
if(qx[i] & (1 << j)) {
curX += (1 << j);
cur = cur -> insert(new node(curX,curY),0);
}else if(qy[i] & (1 << j)) {
curY += (1 << j);
cur = cur -> insert(new node(curX,curY),1);
}
}
}
ans = sum;
dfs(root,sum);
cout << ans << endl;
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... |