# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
846525 |
2023-09-07T17:36:40 Z |
vjudge1 |
ČVENK (COI15_cvenk) |
C++17 |
|
3000 ms |
69932 KB |
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 18;
const ll INF = (1ll<<60)-1;
struct Line{
ll x, y;
void re(){
cin >> x >> y;
}
bool operator<(const Line &other) const{
return x < other.x;
}
};
ll r(ll n){
if(n==0) return 1e18;
return n & -n;
}
ll f(ll x, ll y, ll cost, vector<array<ll, 3>> &g){
if(x==y){
g.pb({0, 0, cost});
return cost;
}
g.pb({x, y, cost});
if(r(x) < r(y)){
ll c;
if(y == 0)
c = x;
else
c = x - (x & (INF^(r(y)-1)));
return cost + f(x - c, y, c, g);
}
ll c;
if(x == 0)
c = y;
else
c = y - (y & (INF^(r(x)-1)));
return cost + f(x, y - c, c, g);
}
int n;
Line a[N], centro{0, 0};
map<int, vector<int>> co, ro;
map<pair<int, int>, int> is;
void dfs(int x, int y, int w){
// cout << x << ' ' << y << ' ' << w << '\n';
int s = 0, down = 0, right = 0;
for(int i = 0; i < co[y].size(); ++i){
if(co[y][i] <= x) continue;
if(co[y][i] == x){
}else{
down++;
}
}
for(int i = 0; i < ro[x].size(); ++i){
if(ro[x][i] <= y) continue;
if(ro[x][i] == y){
}else{
right++;
}
}
s = is[{x,y}];
// cout << right << ' ' << down << ' ' << s << "F"<< '\n';
// en;
if(max({right, down, w}) <= n/2){
centro.x = x;
centro.y = y;
return;
}
if(down > right){
for(int i = 0; i < co[y].size(); ++i){
if(co[y][i] <= x) continue;
dfs(co[y][i], y, w + s + right);
return;
}
}
for(int i = 0; i < ro[x].size(); ++i){
if(ro[x][i] <= y) continue;
dfs(x, ro[x][i], w + s + down);
return;
}
}
void solve(){
cin >> n;
for(int i = 0; i < n; ++i){
a[i].re();
is[{a[i].x, a[i].y}]++;
}
ll ans = 0;
// vector<array<ll, 3>> Y;
// f(centro.x, centro.y, 0, Y);
// reverse(all(Y));
// Y.pb(Y.back());
for(int i = 0; i < n; ++i){
vector<array<ll, 3>> X;
f(a[i].x, a[i].y, 0, X);
for(auto k: X){
if(k[0] == 0 && k[1] == 0) continue;
co[k[1]].pb(k[0]);
ro[k[0]].pb(k[1]);
}
}
for(auto &v: ro){
sort(all(v.second));
}
for(auto &v: co){
sort(all(v.second));
}
int cur = is[{0, 0}], x = 0, y = 0;
dfs(0, 0, cur);
vector<array<ll, 3>> Y;
f(centro.x, centro.y, 0, Y);
ll s = centro.x + centro.y;
reverse(all(Y));
Y.pb(Y.back());
// en;
// cout << centro.x << ' ' << centro.y << '\n';
for(int i = 0; i < n; ++i){
vector<array<ll, 3>> X;
f(a[i].x, a[i].y, 0, X);
ll s = centro.x + centro.y + a[i].x + a[i].y;
reverse(all(X));
X.pb(X.back());
for(int i = 0; i < min(Y.size(), X.size()); ++i){
if(Y[i][0] == X[i][0] && Y[i][1] == X[i][1]){
s -= X[i][2] + Y[i][2];
}else{
s += abs(X[i][0] - Y[i][0]) + abs(Y[i][1] - X[i][1]);
break;
}
}
ans += s;
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// cin >> tt;
while(tt--){
solve();
// en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message
cvenk.cpp: In function 'void dfs(int, int, int)':
cvenk.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0; i < co[y].size(); ++i){
| ~~^~~~~~~~~~~~~~
cvenk.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < ro[x].size(); ++i){
| ~~^~~~~~~~~~~~~~
cvenk.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i = 0; i < co[y].size(); ++i){
| ~~^~~~~~~~~~~~~~
cvenk.cpp:89:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(int i = 0; i < ro[x].size(); ++i){
| ~~^~~~~~~~~~~~~~
cvenk.cpp: In function 'void solve()':
cvenk.cpp:144:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
144 | for(int i = 0; i < min(Y.size(), X.size()); ++i){
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~
cvenk.cpp:126:25: warning: unused variable 'x' [-Wunused-variable]
126 | int cur = is[{0, 0}], x = 0, y = 0;
| ^
cvenk.cpp:126:32: warning: unused variable 'y' [-Wunused-variable]
126 | int cur = is[{0, 0}], x = 0, y = 0;
| ^
cvenk.cpp:132:6: warning: unused variable 's' [-Wunused-variable]
132 | ll s = centro.x + centro.y;
| ^
cvenk.cpp: In function 'int main()':
cvenk.cpp:160:15: warning: unused variable 'aa' [-Wunused-variable]
160 | int tt = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
302 ms |
6352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3061 ms |
69932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |