Submission #1174732


Source Code Expand

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main {
	public static int Q = 1000;
	public static int N = 8;
	public static int[] c = new int[N];
	public static int[] a = new int[N];
	public static int d;
	public static int t;
	public static IO io = new IO();

	public static boolean DEBUG = true;

	public static double PPT_THRESHOLD = 0;
	public static int MAX_DEPTH = 10;
	public static void input() {
		d = io.nextInt();
		t = io.nextInt();
		for(int i=0;i<N;i++) {
			c[i] = io.nextInt();
		}
		for(int i=0;i<N;i++) {
			a[i] = io.nextInt();
		}
	}
	public static void main(String[] args) throws Exception {
		Thread.setDefaultUncaughtExceptionHandler((t,e)->System.err.flush());
		for(int i=0;i<Q;i++) {
			input();
			String move = move();
			io.println(move);
			io.flush();
		}
	}
	public static Queue<String> queue = new ArrayDeque<>();
	public static String move() {
		if (queue.isEmpty()) {
			ArrayList<String> sell = sell();
			if (sell == null) {
				int csum = 0;
				for(int i=0;i<N;i++) {
					csum += c[i];
				}
				debug(String.format("%4d:", d * d) + "FAIL " + "sum=" + csum);
			}else{
				queue.addAll(sell);
				double ppt = (double) d * d / sell.size();
				debug(String.format("%4d:", d * d) + sell.size() + "turn " + String.format("%.1fppt", ppt));
			}
		}
		if (!queue.isEmpty()) {
			return queue.poll();
		}
		return "pass";
	}
	public static ArrayList<String> sell() {
		int best = Integer.MAX_VALUE;
		int bestMask = 0;
		for(int i=1;i<1<<N;i++) {
			int sum = 0;
			int need = 0;
			for(int j=0;j<N;j++) {
				if ((i >> j & 1) == 1) {
					sum += c[j];
					if (a[j] != c[j]) {
						need++;
					}
				}
			}
			if (sum == d) {
				if (need < best) {
					best = need;
					bestMask = i;
				}
			}
		}
		if (bestMask <= 0) {
			return null;
		}
		if (best + 1 > t) {
			return null;
		}
		ArrayList<String> res = new ArrayList<>();
		for(int j=0;j<N;j++) {
			if ((bestMask >> j & 1) == 1 && a[j] != c[j]) {
				res.add("fill " + (j + 1));
			}
		}
		String sell = "sell " + Integer.bitCount(bestMask);
		for(int j=0;j<N;j++) {
			if ((bestMask >> j & 1) == 1) {
				sell += " " + (j + 1);
			}
		}
		res.add(sell);
		return res;
	}
	public static void debug(Object o) {
		if (DEBUG) {
			System.err.println(o);
		}
	}
}
class IO extends PrintWriter {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public IO() { this(System.in);}
	public IO(InputStream source) { super(System.out); this.in = source;}
	public IO(InputStream source, OutputStream out) {
		super(out);
		this.in = source;
	}
	public IO(String fileName) throws IOException {
		super(new FileOutputStream(fileName + ".out"), false);
		this.in = new FileInputStream(new File(fileName + ".txt"));
	}
	public IO(String in,String out) throws IOException {
		super(new FileOutputStream(out + ".out"), false);
		this.in = new FileInputStream(new File(in + ".txt"));
	}
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	private static boolean isNewLine(int c) { return c == '\n' || c == '\r';}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public boolean hasNextLine() { while(hasNextByte() && isNewLine(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public char[] nextCharArray(int len) {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		char[] s = new char[len];
		int i = 0;
		int b = readByte();
		while(isPrintableChar(b)) {
			if (i == len) {
				throw new InputMismatchException();
			}
			s[i++] = (char) b;
			b = readByte();
		}
		return s;
	}
	public String nextLine() {
		if (!hasNextLine()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(!isNewLine(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public char nextChar() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		return (char) readByte();
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a;}
	public long[] nextLongArray(int n) { long[] a = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a;}
	public double[] nextDoubleArray(int n) { double[] a = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a;}
	public void nextIntArrays(int[]... a) { for(int i=0;i<a[0].length;i++) for(int j=0;j<a.length;j++) a[j][i] = nextInt();}
	public int[][] nextIntMatrix(int n,int m) { int[][] a = new int[n][]; for(int i=0;i<n;i++) a[i] = nextIntArray(m); return a;}
	public char[][] nextCharMap(int n,int m) { char[][] a = new char[n][]; for(int i=0;i<n;i++) a[i] = nextCharArray(m); return a;}
	public void close() { super.close(); try {in.close();} catch (IOException e) {}}
}

Submission Info

Submission Time
Task A - 石油王Xの憂鬱
User piroz95
Language Java8 (OpenJDK 1.8.0)
Score 3414516
Code Size 6734 Byte
Status AC
Exec Time 364 ms
Memory 30432 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10 test_11 test_12 test_13 test_14 test_15 test_16 test_17 test_18 test_19 test_20 test_21 test_22 test_23 test_24 test_25 test_26 test_27 test_28 test_29 test_30 test_31 test_32 test_33 test_34 test_35 test_36 test_37 test_38 test_39 test_40 test_41 test_42 test_43 test_44 test_45 test_46 test_47 test_48 test_49 test_50
Score / Max Score 70634 / 417500 66365 / 417500 68505 / 417500 71851 / 417500 65959 / 417500 70581 / 417500 80933 / 417500 62614 / 417500 65913 / 417500 73752 / 417500 61363 / 417500 60243 / 417500 72734 / 417500 72060 / 417500 69731 / 417500 60283 / 417500 71705 / 417500 69438 / 417500 71068 / 417500 69054 / 417500 64362 / 417500 57485 / 417500 60676 / 417500 70002 / 417500 67767 / 417500 66814 / 417500 81954 / 417500 77809 / 417500 72689 / 417500 65082 / 417500 76364 / 417500 69873 / 417500 69578 / 417500 65306 / 417500 69135 / 417500 71425 / 417500 68535 / 417500 66722 / 417500 71749 / 417500 65226 / 417500 65657 / 417500 62278 / 417500 62987 / 417500 65226 / 417500 65349 / 417500 64915 / 417500 70295 / 417500 60552 / 417500 69767 / 417500 74151 / 417500
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
test_11 subtask_01_11.txt
test_12 subtask_01_12.txt
test_13 subtask_01_13.txt
test_14 subtask_01_14.txt
test_15 subtask_01_15.txt
test_16 subtask_01_16.txt
test_17 subtask_01_17.txt
test_18 subtask_01_18.txt
test_19 subtask_01_19.txt
test_20 subtask_01_20.txt
test_21 subtask_01_21.txt
test_22 subtask_01_22.txt
test_23 subtask_01_23.txt
test_24 subtask_01_24.txt
test_25 subtask_01_25.txt
test_26 subtask_01_26.txt
test_27 subtask_01_27.txt
test_28 subtask_01_28.txt
test_29 subtask_01_29.txt
test_30 subtask_01_30.txt
test_31 subtask_01_31.txt
test_32 subtask_01_32.txt
test_33 subtask_01_33.txt
test_34 subtask_01_34.txt
test_35 subtask_01_35.txt
test_36 subtask_01_36.txt
test_37 subtask_01_37.txt
test_38 subtask_01_38.txt
test_39 subtask_01_39.txt
test_40 subtask_01_40.txt
test_41 subtask_01_41.txt
test_42 subtask_01_42.txt
test_43 subtask_01_43.txt
test_44 subtask_01_44.txt
test_45 subtask_01_45.txt
test_46 subtask_01_46.txt
test_47 subtask_01_47.txt
test_48 subtask_01_48.txt
test_49 subtask_01_49.txt
test_50 subtask_01_50.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 357 ms 28276 KB
subtask_01_02.txt AC 306 ms 27176 KB
subtask_01_03.txt AC 293 ms 25632 KB
subtask_01_04.txt AC 287 ms 27040 KB
subtask_01_05.txt AC 282 ms 23588 KB
subtask_01_06.txt AC 295 ms 29340 KB
subtask_01_07.txt AC 287 ms 29084 KB
subtask_01_08.txt AC 268 ms 27664 KB
subtask_01_09.txt AC 290 ms 25684 KB
subtask_01_10.txt AC 298 ms 26912 KB
subtask_01_11.txt AC 295 ms 24992 KB
subtask_01_12.txt AC 333 ms 27736 KB
subtask_01_13.txt AC 364 ms 27796 KB
subtask_01_14.txt AC 314 ms 30140 KB
subtask_01_15.txt AC 315 ms 25752 KB
subtask_01_16.txt AC 313 ms 27672 KB
subtask_01_17.txt AC 337 ms 27336 KB
subtask_01_18.txt AC 324 ms 27752 KB
subtask_01_19.txt AC 289 ms 24912 KB
subtask_01_20.txt AC 334 ms 29676 KB
subtask_01_21.txt AC 291 ms 27876 KB
subtask_01_22.txt AC 307 ms 29476 KB
subtask_01_23.txt AC 290 ms 24940 KB
subtask_01_24.txt AC 289 ms 25688 KB
subtask_01_25.txt AC 290 ms 26852 KB
subtask_01_26.txt AC 341 ms 27640 KB
subtask_01_27.txt AC 296 ms 25712 KB
subtask_01_28.txt AC 333 ms 26716 KB
subtask_01_29.txt AC 322 ms 27764 KB
subtask_01_30.txt AC 302 ms 27544 KB
subtask_01_31.txt AC 290 ms 25372 KB
subtask_01_32.txt AC 292 ms 26912 KB
subtask_01_33.txt AC 311 ms 27784 KB
subtask_01_34.txt AC 272 ms 27548 KB
subtask_01_35.txt AC 304 ms 27296 KB
subtask_01_36.txt AC 299 ms 26008 KB
subtask_01_37.txt AC 323 ms 23908 KB
subtask_01_38.txt AC 327 ms 28080 KB
subtask_01_39.txt AC 301 ms 27868 KB
subtask_01_40.txt AC 281 ms 23708 KB
subtask_01_41.txt AC 325 ms 26736 KB
subtask_01_42.txt AC 317 ms 30432 KB
subtask_01_43.txt AC 327 ms 26548 KB
subtask_01_44.txt AC 304 ms 24984 KB
subtask_01_45.txt AC 329 ms 27672 KB
subtask_01_46.txt AC 318 ms 25656 KB
subtask_01_47.txt AC 327 ms 28008 KB
subtask_01_48.txt AC 316 ms 25824 KB
subtask_01_49.txt AC 306 ms 27968 KB
subtask_01_50.txt AC 304 ms 25320 KB