ソースコード 拡げる

Copy
```import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.*;

public class Main {
private static final int mod = (int)1e9+7;

final Random random = new Random(0);
final IOFast io = new IOFast();

/// MAIN CODE
public void run() throws IOException {
//		int TEST_CASE = Integer.parseInt(new String(io.nextLine()).trim());
int TEST_CASE = 1;
while(TEST_CASE-- != 0) {
int a = io.nextInt();
int b = io.nextInt();
int ans = 100;
for(int i = 0, j = a; ; i++, j = (j + 1) % 10) {
if(j == b) {
ans = Math.min(ans, i);
break;
}
}
for(int i = 0, j = a; ; i++, j = (j + 9) % 10) {
if(j == b) {
ans = Math.min(ans, i);
break;
}
}
io.out.println(ans);
}
}

/// TEMPLATE
static int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); }
static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); }

static <T> void swap(T[] x, int i, int j) {
T t = x[i];
x[i] = x[j];
x[j] = t;
}

static void swap(int[] x, int i, int j) {
int t = x[i];
x[i] = x[j];
x[j] = t;
}

int[] cnt = new int[(1<<16)+1];
int[] ys = new int[xs.length];

for(int j = 0; j <= 16; j += 16) {
Arrays.fill(cnt, 0);
for(int x : xs) { cnt[(x>>j&0xFFFF)+1]++; }
for(int i = 1; i < cnt.length; i++) { cnt[i] += cnt[i-1]; }
for(int x : xs) { ys[cnt[x>>j&0xFFFF]++] = x; }
{ final int[] t = xs; xs = ys; ys = t; }
}
}

int[] cnt = new int[(1<<16)+1];
long[] ys = new long[xs.length];

for(int j = 0; j <= 48; j += 16) {
Arrays.fill(cnt, 0);
for(long x : xs) { cnt[(int)(x>>j&0xFFFF)+1]++; }
for(int i = 1; i < cnt.length; i++) { cnt[i] += cnt[i-1]; }
for(long x : xs) { ys[cnt[(int)(x>>j&0xFFFF)]++] = x; }
{ final long[] t = xs; xs = ys; ys = t; }
}
}

static void arrayIntSort(int[][] x, int... keys) {
Arrays.sort(x, new ArrayIntsComparator(keys));
}

static class ArrayIntsComparator implements Comparator<int[]> {
final int[] KEY;

public ArrayIntsComparator(int... key) {
KEY = key;
}

@Override
public int compare(int[] o1, int[] o2) {
for(int k : KEY) if(o1[k] != o2[k]) return o1[k] - o2[k];
return 0;
}
}

static class ArrayIntComparator implements Comparator<int[]> {
final int KEY;

public ArrayIntComparator(int key) {
KEY = key;
}

@Override
public int compare(int[] o1, int[] o2) {
return o1[KEY] - o2[KEY];
}
}

void main() throws IOException {
//		IOFast.setFileIO("rle-size.in", "rle-size.out");
try {
run();
}
catch (EndOfFileRuntimeException e) { }
io.out.flush();
}

public static void main(String[] args) throws IOException {
new Main().main();
}

static class EndOfFileRuntimeException extends RuntimeException {
private static final long serialVersionUID = -8565341110209207657L; }

static
public class IOFast {
private PrintWriter out = new PrintWriter(System.out);

void setFileIO(String ins, String outs) throws IOException {
out.flush();
out.close();
in.close();
out = new PrintWriter(new FileWriter(outs));
}

//		private static final int BUFFER_SIZE = 50 * 200000;
private static final char[] buffer = new char[1024 * 8];
private static char[] str = new char[500*8*2];
private static boolean[] isDigit = new boolean[256];
private static boolean[] isSpace = new boolean[256];
private static boolean[] isLineSep = new boolean[256];

static {
for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }
isDigit['-'] = true;
isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
isLineSep['\r'] = isLineSep['\n'] = true;
}

public int read() throws IOException {
pos = 0;
if(readLen <= 0) { throw new EndOfFileRuntimeException(); }
}
return buffer[pos++];
}

public int nextInt() throws IOException {
int len = 0;
str[len++] = nextChar();

int i = 0;
int ret = 0;
if(str[0] == '-') { i = 1; }
for(; i < len; i++) ret = ret * 10 + str[i] - '0';
if(str[0] == '-') { ret = -ret; }
return ret;
//			return Integer.parseInt(nextString());
}

public long nextLong() throws IOException {
int len = 0;
str[len++] = nextChar();

int i = 0;
long ret = 0;
if(str[0] == '-') { i = 1; }
for(; i < len; i++) ret = ret * 10 + str[i] - '0';
if(str[0] == '-') { ret = -ret; }
return ret;
//			return Long.parseLong(nextString());
}

public char nextChar() throws IOException {
while(true) {
if(!isSpace[c]) { return (char)c; }
}
}

int reads(int len, boolean[] accept) throws IOException {
try {
while(true) {
if(accept[c]) { break; }

if(str.length == len) {
char[] rep = new char[str.length * 3 / 2];
System.arraycopy(str, 0, rep, 0, str.length);
str = rep;
}

str[len++] = (char)c;
}
}
catch(EndOfFileRuntimeException e) { ; }

return len;
}

int reads(char[] cs, int len, boolean[] accept) throws IOException {
try {
while(true) {
if(accept[c]) { break; }
cs[len++] = (char)c;
}
}
catch(EndOfFileRuntimeException e) { ; }

return len;
}

public char[] nextLine() throws IOException {
int len = 0;
str[len++] = nextChar();

try {
if(str[len-1] == '\r') { len--; read(); }
}
catch(EndOfFileRuntimeException e) { ; }

return Arrays.copyOf(str, len);
}

public String nextString() throws IOException {
return new String(next());
}

public char[] next() throws IOException {
int len = 0;
str[len++] = nextChar();
return Arrays.copyOf(str, len);
}

public int next(char[] cs) throws IOException {
int len = 0;
cs[len++] = nextChar();
return len;
}

public double nextDouble() throws IOException {
return Double.parseDouble(nextString());
}

public long[] nextLongArray(final int n) throws IOException {
final long[] res = new long[n];
for(int i = 0; i < n; i++) {
res[i] = nextLong();
}
return res;
}

public int[] nextIntArray(final int n) throws IOException {
final int[] res = new int[n];
for(int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}

public int[][] nextIntArray2D(final int n, final int k) throws IOException {
final int[][] res = new int[n][];
for(int i = 0; i < n; i++) {
res[i] = nextIntArray(k);
}
return res;
}

public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException {
final int[][] res = new int[n][k+1];
for(int i = 0; i < n; i++) {
for(int j = 0; j < k; j++) {
res[i][j] = nextInt();
}
res[i][k] = i;
}
return res;
}

public double[] nextDoubleArray(final int n) throws IOException {
final double[] res = new double[n];
for(int i = 0; i < n; i++) {
res[i] = nextDouble();
}
return res;
}

}

}
```

#### 提出情報

提出日時 2014-08-16 21:05:47+0900 B - 錠 tanzaku Java (OpenJDK 1.7.0) 100 7769 Byte AC 443 ms 20536 KB

#### ジャッジ結果

セット名 all

 AC × 90
セット名 テストケース
all 0_1.txt, 0_2.txt, 0_3.txt, 0_4.txt, 0_5.txt, 0_6.txt, 0_7.txt, 0_8.txt, 0_9.txt, 1_0.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 1_6.txt, 1_7.txt, 1_8.txt, 1_9.txt, 2_0.txt, 2_1.txt, 2_3.txt, 2_4.txt, 2_5.txt, 2_6.txt, 2_7.txt, 2_8.txt, 2_9.txt, 3_0.txt, 3_1.txt, 3_2.txt, 3_4.txt, 3_5.txt, 3_6.txt, 3_7.txt, 3_8.txt, 3_9.txt, 4_0.txt, 4_1.txt, 4_2.txt, 4_3.txt, 4_5.txt, 4_6.txt, 4_7.txt, 4_8.txt, 4_9.txt, 5_0.txt, 5_1.txt, 5_2.txt, 5_3.txt, 5_4.txt, 5_6.txt, 5_7.txt, 5_8.txt, 5_9.txt, 6_0.txt, 6_1.txt, 6_2.txt, 6_3.txt, 6_4.txt, 6_5.txt, 6_7.txt, 6_8.txt, 6_9.txt, 7_0.txt, 7_1.txt, 7_2.txt, 7_3.txt, 7_4.txt, 7_5.txt, 7_6.txt, 7_8.txt, 7_9.txt, 8_0.txt, 8_1.txt, 8_2.txt, 8_3.txt, 8_4.txt, 8_5.txt, 8_6.txt, 8_7.txt, 8_9.txt, 9_0.txt, 9_1.txt, 9_2.txt, 9_3.txt, 9_4.txt, 9_5.txt, 9_6.txt, 9_7.txt, 9_8.txt
ケース名 結果 実行時間 メモリ
0_1.txt AC 405 ms 20520 KB
0_2.txt AC 443 ms 20484 KB
0_3.txt AC 438 ms 20464 KB
0_4.txt AC 423 ms 20392 KB
0_5.txt AC 398 ms 20396 KB
0_6.txt AC 408 ms 20396 KB
0_7.txt AC 403 ms 20524 KB
0_8.txt AC 416 ms 20440 KB
0_9.txt AC 413 ms 20388 KB
1_0.txt AC 437 ms 20496 KB
1_2.txt AC 414 ms 20396 KB
1_3.txt AC 421 ms 20520 KB
1_4.txt AC 431 ms 20536 KB
1_5.txt AC 433 ms 20508 KB
1_6.txt AC 417 ms 20380 KB
1_7.txt AC 410 ms 20520 KB
1_8.txt AC 421 ms 20392 KB
1_9.txt AC 405 ms 20396 KB
2_0.txt AC 414 ms 20384 KB
2_1.txt AC 405 ms 20396 KB
2_3.txt AC 409 ms 20396 KB
2_4.txt AC 421 ms 20392 KB
2_5.txt AC 424 ms 20392 KB
2_6.txt AC 425 ms 20488 KB
2_7.txt AC 428 ms 20396 KB
2_8.txt AC 415 ms 20524 KB
2_9.txt AC 420 ms 20516 KB
3_0.txt AC 409 ms 20520 KB
3_1.txt AC 414 ms 20520 KB
3_2.txt AC 411 ms 20344 KB
3_4.txt AC 415 ms 20524 KB
3_5.txt AC 410 ms 20524 KB
3_6.txt AC 429 ms 20524 KB
3_7.txt AC 432 ms 20392 KB
3_8.txt AC 414 ms 20520 KB
3_9.txt AC 424 ms 20524 KB
4_0.txt AC 414 ms 20508 KB
4_1.txt AC 408 ms 20392 KB
4_2.txt AC 407 ms 20524 KB
4_3.txt AC 410 ms 20484 KB
4_5.txt AC 414 ms 20392 KB
4_6.txt AC 412 ms 20524 KB
4_7.txt AC 409 ms 20380 KB
4_8.txt AC 408 ms 20520 KB
4_9.txt AC 409 ms 20520 KB
5_0.txt AC 416 ms 20488 KB
5_1.txt AC 419 ms 20516 KB
5_2.txt AC 422 ms 20396 KB
5_3.txt AC 413 ms 20396 KB
5_4.txt AC 409 ms 20508 KB
5_6.txt AC 417 ms 20504 KB
5_7.txt AC 414 ms 20412 KB
5_8.txt AC 418 ms 20524 KB
5_9.txt AC 420 ms 20520 KB
6_0.txt AC 418 ms 20520 KB
6_1.txt AC 407 ms 20524 KB
6_2.txt AC 418 ms 20396 KB
6_3.txt AC 417 ms 20520 KB
6_4.txt AC 429 ms 20392 KB
6_5.txt AC 419 ms 20440 KB
6_7.txt AC 432 ms 20388 KB
6_8.txt AC 419 ms 20388 KB
6_9.txt AC 422 ms 20400 KB
7_0.txt AC 421 ms 20512 KB
7_1.txt AC 430 ms 20396 KB
7_2.txt AC 421 ms 20524 KB
7_3.txt AC 420 ms 20524 KB
7_4.txt AC 420 ms 20392 KB
7_5.txt AC 419 ms 20396 KB
7_6.txt AC 434 ms 20388 KB
7_8.txt AC 427 ms 20440 KB
7_9.txt AC 423 ms 20388 KB
8_0.txt AC 429 ms 20516 KB
8_1.txt AC 430 ms 20388 KB
8_2.txt AC 423 ms 20520 KB
8_3.txt AC 430 ms 20392 KB
8_4.txt AC 430 ms 20504 KB
8_5.txt AC 438 ms 20508 KB
8_6.txt AC 424 ms 20388 KB
8_7.txt AC 421 ms 20524 KB
8_9.txt AC 411 ms 20396 KB
9_0.txt AC 417 ms 20452 KB
9_1.txt AC 423 ms 20524 KB
9_2.txt AC 417 ms 20524 KB
9_3.txt AC 420 ms 20396 KB
9_4.txt AC 419 ms 20520 KB
9_5.txt AC 425 ms 20488 KB
9_6.txt AC 419 ms 20396 KB
9_7.txt AC 418 ms 20388 KB
9_8.txt AC 421 ms 20516 KB