Submission #846415

#TimeUsernameProblemLanguageResultExecution timeMemory
846415vjudge1ČVENK (COI15_cvenk)C++17
0 / 100
292 ms524288 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; } }; 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 = x - (x & (INF^(r(y)-1))); return cost + f(x - c, y, c, g); } ll 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(); } vector<array<ll, 3>> X, Y; ll ans = 0; f(a[0].x, a[0].y, 0, X); f(a[1].x, a[1].y, 0, Y); ans = a[0].x + a[1].x + a[0].y + a[1].y; reverse(all(X)); reverse(all(Y)); // for(auto k: X){ // cout << k[0] << ' ' << k[1] << '\n'; // } // en; // for(auto k: Y){ // cout << k[0] << ' ' << k[1] << '\n'; // } // en; Y.pb(Y.back()); 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]){ ans -= X[i][2] + Y[i][2]; }else{ ans += abs(X[i][0] - Y[i][0]) + abs(Y[i][1] - X[i][1]); break; } // cout << 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:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   62 |   for(int i = 0; i < min(Y.size(), X.size()); ++i){
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~
cvenk.cpp: In function 'int main()':
cvenk.cpp:77:15: warning: unused variable 'aa' [-Wunused-variable]
   77 |   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...