Submission #846463

#TimeUsernameProblemLanguageResultExecution timeMemory
846463vjudge1ČVENK (COI15_cvenk)C++17
17 / 100
77 ms2648 KiB
/* 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]; void solve(){ cin >> n; for(int i = 0; i < n; ++i){ a[i].re(); } sort(a, a+n); ll ANS = 1e18; for(int rep = 0; rep < 2; ++rep){ Line centro; centro.x = a[0].x; centro.y = a[0].y; for(int i = 1; i < (n+1)/2; ++i){ vector<array<ll, 3>> X; f(centro.x, centro.y, 0, X); reverse(all(X)); X.pb(X.back()); vector<array<ll, 3>> Y; f(a[i].x, a[i].y, 0, Y); reverse(all(Y)); Y.pb(Y.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]){ continue; }else{ if(X[i][0] == Y[i][0]){ centro.x = X[i][0]; centro.y = min(X[i][1], Y[i][1]); }else{ centro.x = min(X[i][0], Y[i][0]); centro.y = Y[i][1]; } break; } } // cout << centro.x << ' ' << centro.y << '\n'; } 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); 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; } reverse(a, a+n); ANS = min(ans, ANS); } 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 (stderr)

cvenk.cpp: In function 'void solve()':
cvenk.cpp:74:24: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   74 |       for(int i = 0; i < min(Y.size(), X.size()); ++i){
      |                      ~~^~~~~~~~~~~~~~~~~~~~~~~~~
cvenk.cpp:102:24: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
  102 |       for(int i = 0; i < min(Y.size(), X.size()); ++i){
      |                      ~~^~~~~~~~~~~~~~~~~~~~~~~~~
cvenk.cpp: In function 'int main()':
cvenk.cpp:121:15: warning: unused variable 'aa' [-Wunused-variable]
  121 |   int tt = 1, aa;
      |               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...