// Topcoder SRM 570 DIV 2 2 RobotHerbDiv2
import java.util.*;
import java.math.*;
public class RobotHerbDiv2 {
public static void main(String[] args) {
System.out.println(
//
new RobotHerbDiv2().getdist(
1,
null
));
}
public int getdist(int T, int[] a) {
int x = 0;
int y = 0;
int dir = 0;
for (int i = 0; i < T; i++) {
for (int j = 0; j < a.length; j++) {
int n = a[j];
if (dir == 0)
y += n;
else if (dir == 1)
x += n;
else if (dir == 2)
y -= n;
else if (dir == 3)
x -= n;
dir += n;
dir = dir % 4;
}
}
return Math.abs(x) + Math.abs(y);
}
}
No comments:
Post a Comment