結果

問題 No.822 Bitwise AND
ユーザー kuuso1kuuso1
提出日時 2019-04-26 22:58:17
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,638 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 107,008 KB
実行使用メモリ 18,024 KB
最終ジャッジ日時 2024-05-04 00:23:38
合計ジャッジ時間 2,297 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 26 ms
17,512 KB
testcase_02 AC 27 ms
18,024 KB
testcase_03 AC 26 ms
17,536 KB
testcase_04 AC 27 ms
17,636 KB
testcase_05 AC 27 ms
17,520 KB
testcase_06 AC 26 ms
17,516 KB
testcase_07 AC 26 ms
17,768 KB
testcase_08 AC 26 ms
17,772 KB
testcase_09 WA -
testcase_10 AC 26 ms
17,920 KB
testcase_11 AC 26 ms
17,664 KB
testcase_12 AC 26 ms
17,900 KB
testcase_13 AC 26 ms
17,772 KB
testcase_14 AC 26 ms
17,792 KB
testcase_15 AC 26 ms
17,508 KB
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int b = -1;
		if(N != 0){
			for(int j=31;j>=0;j--){
				if( (N >> j) % 2 == 1){
					b = j;
					break;
				}
			}
		}
		if((1L << (b + 1)) <= 2 * K){
			Console.WriteLine("INF");
			return;
		}
		
		int Kmax = 300;
		int Ofs = 2 * Kmax;
		long[] dp = new long[4 * Kmax];
		dp[0 + Ofs] = 1;
		long v = 1;
		for(int i=0;i<31;i++){
			if((N >> i) % 2 == 1){
				v *= 2;
				continue;
			}
			var ndp = new long[4 * Kmax];
			for(int j=0;j< 4 * Kmax;j++){
				if(dp[j] == 0) continue;
				ndp[j] += dp[j];
				if(j + v < 4 * Kmax) ndp[j + v] += dp[j];
				if(j - v >= 0 ) ndp[j - v] += dp[j];
			}
			dp = ndp;
			v *= 2;
		}
		
		long ans = 0;
		for(int i=0;i<=K;i++) ans += dp[i + Ofs];
		Console.WriteLine(ans);
		
	}
	int N,K;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0