結果

問題 No.941 商とあまり
ユーザー uwiuwi
提出日時 2019-12-04 04:26:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 6,908 bytes
コンパイル時間 4,418 ms
コンパイル使用メモリ 85,940 KB
実行使用メモリ 81,360 KB
最終ジャッジ日時 2024-05-06 14:54:01
合計ジャッジ時間 46,605 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 226 ms
45,736 KB
testcase_02 AC 225 ms
45,052 KB
testcase_03 AC 219 ms
45,064 KB
testcase_04 AC 220 ms
44,608 KB
testcase_05 AC 210 ms
44,460 KB
testcase_06 AC 202 ms
44,488 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 214 ms
44,692 KB
testcase_21 AC 206 ms
44,516 KB
testcase_22 AC 201 ms
44,192 KB
testcase_23 AC 55 ms
37,392 KB
testcase_24 AC 55 ms
37,444 KB
testcase_25 AC 53 ms
37,140 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 210 ms
44,752 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 210 ms
44,588 KB
testcase_41 AC 204 ms
44,728 KB
testcase_42 AC 209 ms
44,444 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 212 ms
44,560 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 AC 210 ms
44,696 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 AC 212 ms
44,064 KB
testcase_102 AC 215 ms
44,328 KB
testcase_103 WA -
testcase_104 AC 56 ms
37,144 KB
testcase_105 AC 56 ms
37,172 KB
testcase_106 AC 56 ms
36,744 KB
testcase_107 AC 52 ms
36,844 KB
testcase_108 AC 52 ms
37,268 KB
testcase_109 AC 53 ms
37,312 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 = "2 50\r\n" + 
//			"4 5\r\n" + 
//			"";
	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 = "10 500000 1 1 1 2 2 3 4 5 6 7";
//	String INPUT = "6 500000 5 7 11 13 17 23";
	
	long[][] bit;
	long ct = 0;
	
	void paint(long[] a, int s, int X, int K)
	{
		if(K < 32) {
			for(int i = s;i>>>6 == s>>>6;i+=K) {
				a[i>>>6] |= 1L<<i;
			}
			for(int j = (s>>>6)+1;j <= X>>>6;j++) {
				// s+ak >= j*64
				// a = (j*64-s+k-1)/k
				long first = (j*64-s+K-1)/K;
				long ss = s+first*K&63;
				a[j] |= bit[K][(int)ss];
			}
//			for(int i = s;i <= X;i+=K) {
//				a[i>>>6] |= 1L<<i;
//			}
		}else {
			for(int i = s;i <= X;i+=K) {
				ct++;
				a[i>>>6] |= 1L<<i;
			}
		}
	}
	
	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);
		
		bit = new long[32][32];
		for(int i = 1;i < 32;i++) {
			for(int j = 0;j < i;j++) {
				for(int k = j;k < 64;k+=i) {
					bit[i][j] |= 1L<<k;
				}
			}
		}
		
		long[][] dp = new long[de.all()][X/64+2];
		for(int i = 0;i < de.all();i++) {
			int F = X;
			for(int j = 0;j < f.length;j++) {
				for(int k = de.dec(i)[j];k > 0;k--) {
					F /= f[j][0]+1;
				}
			}
			F++;
			
			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) {
								paint(dp[ni], k*(l+1)+l, F, k);
//								for(int m = k*(l+1)+l;m <= X;m+=k) {
//									dp[ni][m>>>6] |= 1L<<m;
//								}
								if(k%l < 64) {
									if(h<<~(k%l)<0) {
										continue;
									}
									h |= 1L<<(k%l);
								}
								paint(dp[ni], k*(l+1)+l, F, 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