Submission #846527

# Submission time Handle Problem Language Result Execution time Memory
846527 2023-09-07T17:42:31 Z mychecksedad ČVENK (COI15_cvenk) C++17
17 / 100
2644 ms 378312 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, deque<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) co[y].pop_front(), --i;
    else{
      down++;
    }
  }
  for(int i = 0; i < ro[x].size(); ++i){
    if(ro[x][i] <= y) ro[x].pop_front(), --i;
    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){
      dfs(co[y][i], y, w + s + right);
      return;
    }
  }
 for(int i = 0; i < ro[x].size(); ++i){
    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;
  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::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int i = 0; i < co[y].size(); ++i){
      |                  ~~^~~~~~~~~~~~~~
cvenk.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int i = 0; i < ro[x].size(); ++i){
      |                  ~~^~~~~~~~~~~~~~
cvenk.cpp:81:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i = 0; i < co[y].size(); ++i){
      |                    ~~^~~~~~~~~~~~~~
cvenk.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for(int i = 0; i < ro[x].size(); ++i){
      |                 ~~^~~~~~~~~~~~~~
cvenk.cpp: In function 'void solve()':
cvenk.cpp:136:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
  136 |     for(int i = 0; i < min(Y.size(), X.size()); ++i){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~
cvenk.cpp:118:25: warning: unused variable 'x' [-Wunused-variable]
  118 |   int cur = is[{0, 0}], x = 0, y = 0;
      |                         ^
cvenk.cpp:118:32: warning: unused variable 'y' [-Wunused-variable]
  118 |   int cur = is[{0, 0}], x = 0, y = 0;
      |                                ^
cvenk.cpp:124:6: warning: unused variable 's' [-Wunused-variable]
  124 |   ll s = centro.x + centro.y;
      |      ^
cvenk.cpp: In function 'int main()':
cvenk.cpp:152:15: warning: unused variable 'aa' [-Wunused-variable]
  152 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 5952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2644 ms 378312 KB Output isn't correct
2 Halted 0 ms 0 KB -