Submission #1175001


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.Arrays;
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 int step = 0;
	public static IO io = new IO();

	public static boolean DEBUG = false;

	public static int MAX_D = 50; 
	
	public static int HIGH = 30; //狙う客
	public static int LAST = 1000; //このターン以降Dにかかわらず売る
	
	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 {
		for(int i=0;i<Q;i++) {
			step++;
			input();
			String move = move();
			io.println(move);
			io.flush();
		}
	}
	public static Queue<String> queue = new ArrayDeque<>();
	public static String changeMin() {
		int min = Integer.MAX_VALUE;
		int mini = -1;
		for(int i=0;i<N;i++) {
			int x = c[i] * 100 + a[i];
			if (x < min) {
				min = x;
				mini = i;
			}
		}
		return "change " + (mini + 1);
	}
	public static String fillBig() {
		int max2 = 0;
		int maxi2 = -1;
		for(int i=0;i<N;i++) {
			if (a[i] != c[i]) {
				int x = c[i] * 100 - a[i];
				if (x > max2) {
					max2 = x;
					maxi2 = i;
				}
			}
		}
		return "fill " + (maxi2 + 1);
	}
	public static String move() {
		int csum = 0;
		int asum = 0;
		int filled = 0;
		for(int i=0;i<N;i++) {
			csum += c[i];
			asum += a[i];
			if (a[i] == c[i]) {
				filled++;
			}
		}
		debug(String.format("c=%d a=%d f=%d ", csum, asum, filled));
		if (queue.isEmpty()) {
			boolean ok = false;
			if (d >= HIGH || step >= LAST) {
				if (d >= HIGH) {
					debug(String.format("HIGH! d=%d dd=%d t=%d", d, d*d, t));
				}else{
					debug("LAST! ");
				}
				ArrayList<String> sell = sell(99);
				if (sell != null) {
					ok = true;
					queue.addAll(sell);
					debug(String.format("SELL! $=%d t=%d",d*d,sell.size()));
				}
			}
			if (!ok) {
				if (d >= HIGH && t == 1) {
					debug("T_T");
				}
				double currentScore = score(c, a, HIGH, MAX_D);
				Result res = nextBestMove(c, a, HIGH, MAX_D);
				
				if (res.score < 10.0) {
					debug(String.format("VERY LOW! %.1f", currentScore));
					return changeMin();
				}
				if (res.score <= currentScore + 1e-9) {
					debug(String.format("CANNOT IMPROVE %.1f", currentScore));
					debug(Arrays.toString(c));
					return "pass";
				}else{
					debug(String.format("IMPROVE %.1f -> %.1f", currentScore, res.score));
					return res.move;
				}
			}
		}
		if (!queue.isEmpty()) {
			return queue.poll();
		}
		return "pass";
	}
	public static ArrayList<String> sell(int max) {
		int best = Integer.MAX_VALUE;
		int bestMask = 0;
		LOOP: 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) {
					if (c[j] > max) {
						continue LOOP;
					}
					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 || step + best > 1000) {
			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 double score(int[] c,int[] a,int min,int max) {
		//ok[i]のjビット目が1⇔次のターンに新しい客D=j,T=iが来たとき売るのが間に合う
		long[] ok = new long[11]; 
		int filledMask = 0;
		for(int j=0;j<N;j++) {
			if (a[j] == c[j]) {
				filledMask |= 1 << j;
			}
		}
		for(int i=0;i<1<<N;i++) {
			int sum = 0;
			for(int j=0;j<N;j++) {
				if ((i >> j & 1) == 1) {
					sum += c[j];
				}
			}
			int time = Integer.bitCount(i & ~filledMask) + 1;
			for(int j=time+1;j<=10;j++) {
				ok[j] |= 1L << sum;
			}
		}
		double score = 0;
		for(int t=1;t<=10;t++) {
			for(int d=min;d<=max;d++) {
				if ((ok[t] >> d & 1) == 1) {
					score += d * d;
				}
			}
		}
		return score / (max - min + 1) / 10;
	}
	public static Result nextBestMove(int[] c,int[] a,int min,int max) {
		String bestMove = null;
		double bestScore = Double.NEGATIVE_INFINITY;
		//change
		for(int i=0;i<N;i++) {
			int tempc = c[i];
			int tempa = a[i];
			a[i] = 0;
			double sum = 0;
			for(int j=1;j<=10;j++) {
				c[i] = j;
				sum += score(c,a,min,max);
			}
			c[i] = tempc;
			a[i] = tempa;
			double score = sum / 10;
			if (score > bestScore) {
				bestScore = score;
				bestMove = "change " + (i + 1);
			}
		}
		//fill
		for(int i=0;i<N;i++) {
			int tempa = a[i];
			a[i] = c[i];
			double score = score(c,a,min,max);
			if (score > bestScore) {
				bestScore = score;
				bestMove = "fill " + (i + 1);
			}
			a[i] = tempa;
		}
		return new Result(bestMove, bestScore);
	}
	public static int randInt(int min,int max) {
		return (int) (Math.random() * (max - min + 1)) + min;
	}
	public static int lastStep = -1;
	public static void debug(Object o) {
		if (DEBUG) {
			if (lastStep != step) {
				System.err.println();
				System.err.print(step + ".");
				lastStep = step;
			}
			System.err.print(" " + o);
		}
	}
}
class Result {
	String move;
	double score;
	public Result(String move, double score) {
		super();
		this.move = move;
		this.score = score;
	}
}
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 7378044
Code Size 10195 Byte
Status AC
Exec Time 1102 ms
Memory 42720 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 145474 / 417500 147155 / 417500 149459 / 417500 140050 / 417500 148410 / 417500 155885 / 417500 156909 / 417500 149744 / 417500 150857 / 417500 146974 / 417500 150009 / 417500 144249 / 417500 150558 / 417500 146040 / 417500 138156 / 417500 155574 / 417500 141788 / 417500 146746 / 417500 154265 / 417500 143409 / 417500 156876 / 417500 149156 / 417500 139695 / 417500 153591 / 417500 147399 / 417500 146891 / 417500 144224 / 417500 150848 / 417500 149549 / 417500 150077 / 417500 155058 / 417500 139073 / 417500 145543 / 417500 148693 / 417500 150563 / 417500 136089 / 417500 146545 / 417500 148691 / 417500 140588 / 417500 147835 / 417500 148257 / 417500 146158 / 417500 151392 / 417500 142831 / 417500 144342 / 417500 148884 / 417500 149836 / 417500 146298 / 417500 152782 / 417500 138569 / 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 1034 ms 34892 KB
subtask_01_02.txt AC 1011 ms 38888 KB
subtask_01_03.txt AC 1062 ms 35664 KB
subtask_01_04.txt AC 1067 ms 34916 KB
subtask_01_05.txt AC 1033 ms 34360 KB
subtask_01_06.txt AC 1044 ms 37444 KB
subtask_01_07.txt AC 1018 ms 34156 KB
subtask_01_08.txt AC 1079 ms 38128 KB
subtask_01_09.txt AC 1039 ms 36040 KB
subtask_01_10.txt AC 1042 ms 39744 KB
subtask_01_11.txt AC 1065 ms 34156 KB
subtask_01_12.txt AC 1054 ms 35968 KB
subtask_01_13.txt AC 968 ms 35728 KB
subtask_01_14.txt AC 1063 ms 37700 KB
subtask_01_15.txt AC 1051 ms 38288 KB
subtask_01_16.txt AC 989 ms 35244 KB
subtask_01_17.txt AC 1054 ms 37500 KB
subtask_01_18.txt AC 1021 ms 37696 KB
subtask_01_19.txt AC 1039 ms 37308 KB
subtask_01_20.txt AC 1024 ms 32824 KB
subtask_01_21.txt AC 971 ms 33892 KB
subtask_01_22.txt AC 1063 ms 36720 KB
subtask_01_23.txt AC 1088 ms 36892 KB
subtask_01_24.txt AC 1047 ms 34208 KB
subtask_01_25.txt AC 1042 ms 34464 KB
subtask_01_26.txt AC 1059 ms 35464 KB
subtask_01_27.txt AC 977 ms 33812 KB
subtask_01_28.txt AC 1079 ms 35852 KB
subtask_01_29.txt AC 1039 ms 37172 KB
subtask_01_30.txt AC 1098 ms 39276 KB
subtask_01_31.txt AC 1023 ms 35728 KB
subtask_01_32.txt AC 1087 ms 35828 KB
subtask_01_33.txt AC 1050 ms 37132 KB
subtask_01_34.txt AC 1036 ms 35664 KB
subtask_01_35.txt AC 1027 ms 33228 KB
subtask_01_36.txt AC 1075 ms 37940 KB
subtask_01_37.txt AC 1089 ms 34732 KB
subtask_01_38.txt AC 1102 ms 36416 KB
subtask_01_39.txt AC 1057 ms 42720 KB
subtask_01_40.txt AC 1036 ms 34332 KB
subtask_01_41.txt AC 1036 ms 37152 KB
subtask_01_42.txt AC 1042 ms 34812 KB
subtask_01_43.txt AC 1037 ms 38176 KB
subtask_01_44.txt AC 1061 ms 36308 KB
subtask_01_45.txt AC 1073 ms 35504 KB
subtask_01_46.txt AC 1053 ms 36116 KB
subtask_01_47.txt AC 1045 ms 34852 KB
subtask_01_48.txt AC 1074 ms 34116 KB
subtask_01_49.txt AC 982 ms 34380 KB
subtask_01_50.txt AC 1042 ms 36136 KB