General

# Author Problem Lang Verdict Time Memory Sent Judged
12633117 Practice:
m.khooryani
189A - 39 Java 7 Runtime error on test 1 61 ms 0 KB 2015-08-21 22:31:36 2015-08-21 22:31:36

→ Source
import java.awt.Point;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import sun.misc.Queue;

/**
*
* @author Mojtaba
*/
public class Main {

public static void main(String[] args) throws IOException, InterruptedException {
MyScanner in = new MyScanner(System.in);
PrintWriter writer = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder("");

int n = in.nextInt();
int[] a = in.nextIntegerArray(3);
Arrays.sort(a);
if (n % a[0] == 0) {
sb.append(n / a[0]);
} else {
MyClass myClass = bfs(a, n);
sb.append((myClass.depth + (n - myClass.data) / a[0]));
}

writer.println(sb.toString());
writer.close();
in.close();
}

private static MyClass bfs(int[] a, int n) throws InterruptedException {
Queue queue = new Queue();
int depth = 0;
int minus = 0;
queue.enqueue(new MyClass(1, a[1]));
queue.enqueue(new MyClass(1, a[2]));
queue.enqueue(new MyClass(2, a[1] + a[2]));
while (true) {
MyClass data = (MyClass) queue.dequeue();
if ((n - data.data) % a[0] == 0) {
depth = data.depth;
minus = data.data;
break;
}
queue.enqueue(new MyClass(data.depth + 1, data.data + a[1]));
queue.enqueue(new MyClass(data.depth + 1, data.data + a[2]));
queue.enqueue(new MyClass(data.depth + 2, data.data + a[1] + a[2]));
}
return new MyClass(depth, minus);
}
}

class MyClass {

int depth;
int data;

public MyClass(int depth, int data) {
this.depth = depth;
this.data = data;
}
}

class MyScanner {

StringTokenizer tokenizer;

public MyScanner(InputStream stream) {
}

public int nextInt() throws IOException {
return Integer.parseInt(next());
}

public int[] nextIntegerArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}

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

public int nextInt(int radix) throws IOException {
}

public long nextLong() throws IOException {
return Long.parseLong(next());
}

public long nextLong(int radix) throws IOException {
}

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

public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}

public BigInteger nextBigInteger(int radix) throws IOException {
}

public String next() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
return this.next();
}
}

public void close() throws IOException {
}
}

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?