# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
846440 |
2023-09-07T14:46:45 Z |
NotLinux |
ČVENK (COI15_cvenk) |
C++17 |
|
3000 ms |
348 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,ans = 0;
pair < int , int > par(pair < int, int > a){
if((a.first & -a.first) < (a.second & -a.second) and (a.first & -a.first) != 0){
ans += a.first & -a.first;
a.first -= a.first & -a.first;
}
else if((a.second & -a.second) != 0){
ans += a.second & -a.second;
a.second -= a.second & -a.second;
}
else {
ans += a.first & -a.first;
a.first -= a.first & -a.first;
}
return a;
}
int dist(pair < int , int > a , pair < int , int > b){
int ret = 0;
int cnta = __builtin_popcountll(a.first) + __builtin_popcountll(a.second);
int cntb = __builtin_popcountll(b.first) + __builtin_popcountll(b.second);
if(cnta < cntb)swap(a,b);
int diff = cntb - cnta;
while(diff--){
pair < int , int > newa = par(a);
ret += a.first - newa.first + a.second - newa.second;
a = newa;
}
while(a != b){
pair < int , int > newa = par(a);
pair < int , int > newb = par(b);
if(par(a) == par(b)){
if(a.first == b.first){
ret -= min(a.second,b.second) - newa.second + 1;
}
else if(a.second == b.second){
ret -= min(a.first,b.first) - newa.first + 1;
}
}
ret += a.first - newa.first + a.second - newa.second;
ret += b.first - newb.first + b.second - newb.second;
a = newa;
b = newb;
}
return ret;
}
void solve(){
int n;cin >> n;
pair < int , int > a,b;
cin >> a.first >> a.second;
cin >> b.first >> b.second;
cout << dist(a,b) << endl;
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3053 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3021 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |