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.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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.LinkedList;
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 {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public MyScanner(InputStream stream) {
        this.reader = new BufferedReader(new InputStreamReader(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 {
        return Integer.parseInt(next(), radix);
    }

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

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

    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 {
        return new BigInteger(next(), radix);
    }

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

    public void close() throws IOException {
        this.reader.close();
    }
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details