結果

問題 No.941 商とあまり
ユーザー uwiuwi
提出日時 2019-12-04 03:46:01
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 5,955 bytes
コンパイル時間 4,635 ms
コンパイル使用メモリ 89,136 KB
実行使用メモリ 134,748 KB
最終ジャッジ日時 2024-11-28 19:21:54
合計ジャッジ時間 74,414 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 306 ms
63,044 KB
testcase_01 AC 201 ms
134,748 KB
testcase_02 AC 187 ms
63,496 KB
testcase_03 AC 196 ms
56,424 KB
testcase_04 AC 189 ms
56,152 KB
testcase_05 AC 166 ms
55,764 KB
testcase_06 AC 193 ms
56,088 KB
testcase_07 AC 213 ms
57,084 KB
testcase_08 AC 209 ms
56,516 KB
testcase_09 AC 206 ms
56,044 KB
testcase_10 AC 233 ms
56,400 KB
testcase_11 AC 229 ms
56,444 KB
testcase_12 AC 195 ms
56,388 KB
testcase_13 AC 317 ms
56,048 KB
testcase_14 AC 248 ms
56,416 KB
testcase_15 AC 289 ms
56,088 KB
testcase_16 AC 373 ms
58,440 KB
testcase_17 AC 511 ms
58,376 KB
testcase_18 AC 867 ms
60,528 KB
testcase_19 TLE -
testcase_20 AC 176 ms
55,940 KB
testcase_21 AC 173 ms
55,736 KB
testcase_22 AC 188 ms
55,968 KB
testcase_23 AC 48 ms
50,524 KB
testcase_24 AC 49 ms
50,520 KB
testcase_25 AC 50 ms
50,032 KB
testcase_26 AC 253 ms
56,212 KB
testcase_27 AC 241 ms
56,176 KB
testcase_28 AC 250 ms
56,344 KB
testcase_29 AC 405 ms
58,200 KB
testcase_30 AC 404 ms
58,404 KB
testcase_31 AC 247 ms
56,396 KB
testcase_32 AC 183 ms
56,704 KB
testcase_33 AC 189 ms
56,104 KB
testcase_34 AC 854 ms
60,576 KB
testcase_35 AC 783 ms
58,352 KB
testcase_36 AC 218 ms
56,508 KB
testcase_37 AC 235 ms
56,260 KB
testcase_38 AC 233 ms
56,248 KB
testcase_39 AC 242 ms
56,344 KB
testcase_40 AC 183 ms
55,776 KB
testcase_41 AC 181 ms
55,604 KB
testcase_42 AC 191 ms
56,052 KB
testcase_43 AC 227 ms
56,284 KB
testcase_44 AC 221 ms
56,400 KB
testcase_45 AC 1,758 ms
62,832 KB
testcase_46 AC 745 ms
60,492 KB
testcase_47 AC 238 ms
56,516 KB
testcase_48 AC 178 ms
55,860 KB
testcase_49 AC 233 ms
56,224 KB
testcase_50 AC 233 ms
56,244 KB
testcase_51 AC 259 ms
56,468 KB
testcase_52 AC 224 ms
56,208 KB
testcase_53 AC 223 ms
56,364 KB
testcase_54 TLE -
testcase_55 TLE -
testcase_56 AC 1,993 ms
67,412 KB
testcase_57 TLE -
testcase_58 TLE -
testcase_59 AC 221 ms
56,468 KB
testcase_60 AC 233 ms
56,460 KB
testcase_61 AC 201 ms
55,976 KB
testcase_62 AC 262 ms
56,460 KB
testcase_63 AC 242 ms
56,444 KB
testcase_64 AC 250 ms
56,024 KB
testcase_65 AC 258 ms
56,376 KB
testcase_66 AC 213 ms
56,156 KB
testcase_67 AC 304 ms
56,044 KB
testcase_68 AC 235 ms
56,340 KB
testcase_69 AC 351 ms
56,156 KB
testcase_70 AC 414 ms
56,344 KB
testcase_71 AC 305 ms
56,352 KB
testcase_72 AC 295 ms
56,352 KB
testcase_73 AC 434 ms
56,004 KB
testcase_74 AC 597 ms
58,280 KB
testcase_75 AC 466 ms
58,344 KB
testcase_76 AC 439 ms
56,268 KB
testcase_77 AC 320 ms
56,448 KB
testcase_78 AC 639 ms
58,052 KB
testcase_79 AC 746 ms
58,292 KB
testcase_80 AC 793 ms
58,468 KB
testcase_81 AC 953 ms
58,368 KB
testcase_82 AC 781 ms
58,276 KB
testcase_83 AC 446 ms
58,308 KB
testcase_84 AC 729 ms
58,444 KB
testcase_85 AC 1,167 ms
60,600 KB
testcase_86 AC 723 ms
58,060 KB
testcase_87 AC 655 ms
58,468 KB
testcase_88 AC 779 ms
58,044 KB
testcase_89 AC 1,851 ms
62,764 KB
testcase_90 AC 1,496 ms
60,464 KB
testcase_91 AC 1,652 ms
60,528 KB
testcase_92 AC 1,632 ms
62,680 KB
testcase_93 AC 1,477 ms
60,720 KB
testcase_94 AC 1,769 ms
62,688 KB
testcase_95 TLE -
testcase_96 AC 1,188 ms
60,680 KB
testcase_97 AC 1,004 ms
60,688 KB
testcase_98 AC 186 ms
56,172 KB
testcase_99 AC 1,166 ms
60,500 KB
testcase_100 AC 1,826 ms
62,696 KB
testcase_101 AC 176 ms
55,836 KB
testcase_102 AC 176 ms
55,792 KB
testcase_103 TLE -
testcase_104 AC 48 ms
50,116 KB
testcase_105 AC 48 ms
50,128 KB
testcase_106 AC 55 ms
50,596 KB
testcase_107 AC 48 ms
50,272 KB
testcase_108 AC 49 ms
50,528 KB
testcase_109 AC 49 ms
57,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Adv19D4_3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
//	String INPUT = "4 500000 65 66 67 68";
//	String INPUT = "6 500000 1 2 3 4 5 6";
//	String INPUT = "4 500000 3 4 5 6";
//	String INPUT = "18 500000 1 1 1 1 1  1 1 1 1 1  1 1 1 1 1  1 1 1";
//	String INPUT = "6 500000 5 7 11 13 17 23";
	
	int max =0;
	
	void solve()
	{
		int n = ni(), X = ni();
		int[] a = na(n);
		double u = 1;
		for(int v : a) {
			u *= v+1;
			if(u-1 > X) {
				for(int i = 0;i < X;i++) {
					out.print(0);
				}
				out.println();
				return;
			}
		}
		
		Arrays.sort(a);
		int[][] f = uniqcount(a);
		int[] fi = new int[f.length];
		for(int i = 0;i < f.length;i++)fi[i] = f[i][1] + 1;
		Denom de = new Denom(fi);
		
		long[][] dp = new long[de.all()][X/64+2];
		for(int i = 0;i < de.all();i++) {
			for(int j = 0;j < f.length;j++) {
				if(de.in(i, j, 1)) {
					int ni = de.add(i, j, 1);
					if(i == 0) {
						dp[ni][f[j][0]>>>6] |= 1L<<f[j][0];
					}else {
//						tr(i, j, ni);
						int l = f[j][0];
//						int ct = 0;
						long h = 0;
						for(int k = 1;(long)k*(l+1)+l <= X;k++) {
							if(dp[i][k>>>6]<<~k<0) {
//								tr(k);
								for(int m = k*(l+1)+l;m <= X;m+=k) {
//									ct++;
									dp[ni][m>>>6] |= 1L<<m;
								}
								if(k%l < 64) {
									if(h<<~(k%l)<0) {
										continue;
									}
									h |= 1L<<(k%l);
								}
								for(int m = k*(l+1)+l;m <= X;m+=l) {
//									ct++;
									dp[ni][m>>>6] |= 1L<<m;
								}
							}
						}
//						tr(i, j, ni, ct);
					}
				}
			}
		}
		for(int i = 1;i <= X;i++) {
			out.print(dp[de.all()-1][i>>>6]<<~i<0 ? 1 : 0);
		}
		out.println();
	}
	
	public static int[] getind(int[][] a, int ind) {
		int[] b = new int[a.length];
		for(int i = 0;i < a.length;i++)b[i] = a[i][ind];
		return b;
	}

	
	public static class Denom
	{
		int[] a;
		int[] ia;
		
		Denom(int... ia)
		{
			this.ia = ia;
			int n = ia.length;
			a = new int[n+1];
			a[0] = 1;
			for(int i = 0;i < n;i++){
				a[i+1] = a[i] * ia[i];
			}
		}
		
		int[] dec(int code)
		{
			int[] ret = new int[a.length-1];
			for(int i = 0;i < a.length-1;i++) {
				ret[i] = code % a[i+1] / a[i];
			}
			return ret;
		}
		
		int ind(int... x)
		{
			assert x.length == ia.length;
			int ret = 0;
			for(int i = 0;i < x.length;i++){
				ret += x[i] * a[i];
			}
			return ret;
		}
		
		boolean in(int code, int which, int plus)
		{
			int v = v(code, which);
			return 0 <= v + plus && v + plus < ia[which];
		}
		
		int v(int code, int which)
		{
			return code / a[which] % ia[which];
		}
		
		int add(int code, int which, int plus)
		{
			return code + a[which] * plus;
		}
		
		int update(int code, int which, int val)
		{
			return code + (-code / a[which] % ia[which] + val) * a[which];
		}
		
		int all() { return a[a.length-1]; }
	}

	
	public static int[][] uniqcount(int[] a)
	{
		int n = a.length;
		int p = 0;
		int[][] b = new int[n][];
		for(int i = 0;i < n;i++){
			if(i == 0 || a[i] != a[i-1])b[p++] = new int[]{a[i], 0};
			b[p-1][1]++;
		}
		return Arrays.copyOf(b, p);
	}

	
	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//		Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){
//			@Override
//			public void run() {
//				long s = System.currentTimeMillis();
//				solve();
//				out.flush();
//				if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//			}
//		};
//		t.start();
//		t.join();
	}
	
	public static void main(String[] args) throws Exception { new Adv19D4_3().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i = 0;i < n;i++)a[i] = nl();
		return a;
	}
	
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[][] nmi(int n, int m) {
		int[][] map = new int[n][];
		for(int i = 0;i < n;i++)map[i] = na(m);
		return map;
	}
	
	private int ni() { return (int)nl(); }
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}
0