| Task: | Labyrintti |
| Sender: | |
| Submission time: | 2015-10-10 22:39:16 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | RUNTIME ERROR | 0 |
| #2 | RUNTIME ERROR | 0 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.05 s | 1 | details |
| #2 | RUNTIME ERROR | 0.05 s | 1 | details |
| #3 | RUNTIME ERROR | 0.06 s | 1 | details |
| #4 | ACCEPTED | 0.06 s | 1 | details |
| #5 | ACCEPTED | 0.05 s | 1 | details |
| #6 | RUNTIME ERROR | 0.05 s | 2 | details |
| #7 | RUNTIME ERROR | 0.06 s | 2 | details |
| #8 | RUNTIME ERROR | 0.06 s | 2 | details |
| #9 | RUNTIME ERROR | 0.06 s | 2 | details |
| #10 | RUNTIME ERROR | 0.07 s | 2 | details |
| #11 | RUNTIME ERROR | 0.05 s | 3 | details |
| #12 | RUNTIME ERROR | 0.06 s | 3 | details |
| #13 | RUNTIME ERROR | 0.05 s | 3 | details |
| #14 | RUNTIME ERROR | 0.05 s | 3 | details |
| #15 | RUNTIME ERROR | 0.06 s | 3 | details |
Code
#include <iostream>
#include <cstdlib>
#include <complex>
using namespace std;
typedef long long ll;
typedef complex<ll> V;
bool start(V pt) {
ll x=pt.real();
ll y=pt.imag();
return y<=-1 && y>=-3 && x<=1 && x>=-5;
}
const V ds[]={
V(-1,0),
V(0,1),
V(1,0),
V(0,-1)
};
bool betw(V a, V b, V v) {
// cout<<"betw "<<a<<' '<<b<<' '<<v<<'\n';
ll x1=a.real(),x2=b.real();
ll y1=a.imag(),y2=b.imag();
ll x=v.real(),y=v.imag();
if (x1>x2) swap(x1,x2);
if (y1>y2) swap(y1,y2);
return x>=x1 && x<=x2 && y>=y1 && y<=y2;
}
bool inR(V cur, V pt, V dir, V pdir, ll w1, ll w2, ll w3) {
V c1 = cur - w1*dir;
V c2 = cur + w2*pdir + w3*dir;
return betw(c1,c2,pt);
}
ll dist(V a, V b) {
V v=b-a;
return llabs(v.real()) + llabs(v.imag());
}
int main() {
ll x1,y1,x2,y2;
cin>>y1>>x1>>y2>>x2;
V v1(x1,y1);
V v2(x2,y2);
if (start(v1)&&start(v2)) {
cout<<dist(v1,v2)<<'\n';
}
int step=0;
ll len=1;
V cur(1,-1);
int d=0;
bool found = 0;
ll res=0;
while(1) {
ll add;
ll w1,w2,w3;
if (step <= 1) {
len=1;
add = 2*len;
w1 = len;
w2 = 2*len;
w3 = add+4*len;
if (step==1) {
w1=2;
w2=4*len;
w3=8*len;
}
} else {
len *=2;
add = len+2;
w1 = 4*len - len/4;
w2 = 8*len - len/2;
w3 = 16*len - len;
}
++step;
V dir=ds[d];
V pdir=ds[(d+3)%4];
++d;
d%=4;
// cout<<cur<<' '<<add<<' '<<w1<<' '<<w2<<' '<<dir<<' '<<pdir<<" ; "<<res<<'\n';
// cout<<"from "<<cur<<" towards "<<add*dir<<" w1w2w3: "<<w1<<' '<<w2<<' '<<w3<<'\n';
if (!found) {
if (inR(cur, v1, dir, pdir, w1, w2, w3)
&& inR(cur, v2, dir, pdir, w1, w2, w3)) {
// cout<<"both\n";
cout<<dist(v1,v2)<<'\n';
return 0;
}
bool in1 = inR(cur, v1, dir, pdir, w1, w2, add-1);
bool in2 = inR(cur, v2, dir, pdir, w1, w2, add-1);
if (in1 || in2) {
// cout<<"found1\n";
found = 1;
if (in1) swap(v1,v2);
}
} else {
if (inR(cur, v1, dir, pdir, w1, w2, w3)) {
res += dist(v1,v2);
cout<<res<<'\n';
return res;
}
}
cur += add*dir;
if (found) res += dist(cur,v2), v2=cur;
}
}
Test details
Test 1
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 6 -1 8 -2 |
| correct output |
|---|
| 3 |
| user output |
|---|
| 3 |
Test 2
Group: 1
Verdict: RUNTIME ERROR
| input |
|---|
| -8 2 8 -9 |
| correct output |
|---|
| 27 |
| user output |
|---|
| 29 |
Test 3
Group: 1
Verdict: RUNTIME ERROR
| 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: RUNTIME ERROR
| input |
|---|
| -156 226 -9 7 |
| correct output |
|---|
| 438 |
| user output |
|---|
| 438 |
Test 7
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 403 265 10 0 |
| correct output |
|---|
| 1100 |
| user output |
|---|
| 1100 |
Test 8
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 146 462 9 -3 |
| correct output |
|---|
| 1160 |
| user output |
|---|
| 650 |
Test 9
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 223 82 -1 5 |
| correct output |
|---|
| 725 |
| user output |
|---|
| 333 |
Test 10
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 1 390 -5 2 |
| correct output |
|---|
| 436 |
| user output |
|---|
| 436 |
Test 11
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| -540305713988379 -580514137141... |
| correct output |
|---|
| 1233409841814111 |
| user output |
|---|
| 1233409841814111 |
Test 12
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| -156703691254895 -816797859965... |
| correct output |
|---|
| 1086091541904259 |
| user output |
|---|
| 1086091541904259 |
Test 13
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| -438806811971369 -748477242640... |
| correct output |
|---|
| 1299874045296142 |
| user output |
|---|
| 1299874045296142 |
Test 14
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 939351840049839 -9541207461566... |
| correct output |
|---|
| 2118652567575152 |
| user output |
|---|
| 2118652567575152 |
Test 15
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| -840127817790022 1113515308437... |
| correct output |
|---|
| 1007774343975947 |
| user output |
|---|
| 1007774343975947 |
