結果
問題 |
No.822 Bitwise AND
|
ユーザー |
![]() |
提出日時 | 2019-04-26 22:58:17 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,638 bytes |
コンパイル時間 | 843 ms |
コンパイル使用メモリ | 115,544 KB |
実行使用メモリ | 26,052 KB |
最終ジャッジ日時 | 2024-11-25 05:59:58 |
合計ジャッジ時間 | 1,906 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 3 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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));} }