| Task: | Labyrintti |
| Sender: | Henrik Lievonen |
| Submission time: | 2015-10-10 12:22:19 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 12 |
| #2 | ACCEPTED | 29 |
| #3 | ACCEPTED | 59 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.05 s | 1 | details |
| #2 | ACCEPTED | 0.05 s | 1 | details |
| #3 | ACCEPTED | 0.05 s | 1 | details |
| #4 | ACCEPTED | 0.06 s | 1 | details |
| #5 | ACCEPTED | 0.06 s | 1 | details |
| #6 | ACCEPTED | 0.05 s | 2 | details |
| #7 | ACCEPTED | 0.06 s | 2 | details |
| #8 | ACCEPTED | 0.05 s | 2 | details |
| #9 | ACCEPTED | 0.05 s | 2 | details |
| #10 | ACCEPTED | 0.06 s | 2 | details |
| #11 | ACCEPTED | 0.05 s | 3 | details |
| #12 | ACCEPTED | 0.06 s | 3 | details |
| #13 | ACCEPTED | 0.05 s | 3 | details |
| #14 | ACCEPTED | 0.06 s | 3 | details |
| #15 | ACCEPTED | 0.05 s | 3 | details |
Compiler report
input/code.cpp: In function 'rect getSectorBounds(int)': input/code.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type] } ^
Code
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
struct rect {
ll x1, y1, x2, y2;
rect(ll a, ll b, ll c, ll d) :x1(a), y1(b), x2(c), y2(d) {}
};
vector<ll> bounds;
ll pow2(int i) {
return 1ll << i;
}
rect getSectorBounds(int i) {
switch (i % 4) {
case 0:
return rect(bounds[i+1], bounds[i+4]+1, bounds[i+3]-1,bounds[i]-1);
case 1:
return rect(bounds[i + 4] + 1, bounds[i + 3] + 1, bounds[i] - 1, bounds[i+1]);
case 2:
return rect(bounds[i + 3] + 1, bounds[i] + 1, bounds[i + 1], bounds[i + 4] - 1);
case 3:
return rect(bounds[i] + 1, bounds[i + 1], bounds[i + 4] - 1, bounds[i + 3] - 1);
}
//return rect(0, 0, 0, 0);
}
int getSector(ll x, ll y) {
for (int i = 0; ; i++) {
rect r = getSectorBounds(i);
if (r.x1 <= x && x <= r.x2 && r.y1 <= y && y <= r.y2)
return i;
}
}
int main() {
bounds.push_back(0);
bounds.push_back(0);
bounds.push_back(0);
bounds.push_back(2);
for (int i = 4; i < 60;) {
bounds.push_back(bounds[i - 2] - pow2(i-2)); i++;
bounds.push_back(bounds[i - 2] - pow2(i-2)); i++;
bounds.push_back(bounds[i - 2] + pow2(i-2)); i++;
bounds.push_back(bounds[i - 2] + pow2(i-2)); i++;
}
ll x1, y1, x2, y2;
cin >> y1 >> x1 >> y2 >> x2;
if (getSector(x1, y1) > getSector(x2, y2)) {
swap(x1, x2);
swap(y1, y2);
}
ll res = 0;
while (getSector(x1, y1) != getSector(x2, y2)) {
int s = getSector(x1, y1);
rect b = getSectorBounds(s);
switch (s%4) {
case 0:
res += x1 - b.x1 + 1;
x1 = b.x1 - 1;
break;
case 1:
res += b.y2 - y1 + 1;
y1 = b.y2 + 1;
break;
case 2:
res += b.x2 - x1 + 1;
x1 = b.x2 + 1;
break;
case 3:
res += y1 - b.y1 + 1;
y1 = b.y1 - 1;
break;
}
}
res += abs(x1 - x2) + abs(y1 - y2);
cout << res;
}Test details
Test 1
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 6 -1 8 -2 |
| correct output |
|---|
| 3 |
| user output |
|---|
| 3 |
Test 2
Group: 1
Verdict: ACCEPTED
| input |
|---|
| -8 2 8 -9 |
| correct output |
|---|
| 27 |
| user output |
|---|
| 27 |
Test 3
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 3 2 -5 -1 |
| correct output |
|---|
| 13 |
| user output |
|---|
| 13 |
Test 4
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 4 4 2 7 |
| correct output |
|---|
| 5 |
| user output |
|---|
| 5 |
Test 5
Group: 1
Verdict: ACCEPTED
| input |
|---|
| -5 4 -6 -3 |
| correct output |
|---|
| 8 |
| user output |
|---|
| 8 |
Test 6
Group: 2
Verdict: ACCEPTED
| input |
|---|
| -156 226 -9 7 |
| correct output |
|---|
| 438 |
| user output |
|---|
| 438 |
Test 7
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 403 265 10 0 |
| correct output |
|---|
| 1100 |
| user output |
|---|
| 1100 |
Test 8
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 146 462 9 -3 |
| correct output |
|---|
| 1160 |
| user output |
|---|
| 1160 |
Test 9
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 223 82 -1 5 |
| correct output |
|---|
| 725 |
| user output |
|---|
| 725 |
Test 10
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 1 390 -5 2 |
| correct output |
|---|
| 436 |
| user output |
|---|
| 436 |
Test 11
Group: 3
Verdict: ACCEPTED
| input |
|---|
| -540305713988379 -580514137141... |
| correct output |
|---|
| 1233409841814111 |
| user output |
|---|
| 1233409841814111 |
Test 12
Group: 3
Verdict: ACCEPTED
| input |
|---|
| -156703691254895 -816797859965... |
| correct output |
|---|
| 1086091541904259 |
| user output |
|---|
| 1086091541904259 |
Test 13
Group: 3
Verdict: ACCEPTED
| input |
|---|
| -438806811971369 -748477242640... |
| correct output |
|---|
| 1299874045296142 |
| user output |
|---|
| 1299874045296142 |
Test 14
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 939351840049839 -9541207461566... |
| correct output |
|---|
| 2118652567575152 |
| user output |
|---|
| 2118652567575152 |
Test 15
Group: 3
Verdict: ACCEPTED
| input |
|---|
| -840127817790022 1113515308437... |
| correct output |
|---|
| 1007774343975947 |
| user output |
|---|
| 1007774343975947 |
