結果

問題 No.685 Logical Operations
ユーザー tsutajtsutaj
提出日時 2018-05-12 02:31:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,547 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 32,952 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 18:17:10
合計ジャッジ時間 1,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
using namespace std;

int dp[65][4][4];
const int MOD = 1000000007;

int main() {
    long long int N; scanf("%lld", &N);
    int M = 60;
    dp[M+1][0][0] = 1;

    for(int B=M; B>=0; B--) {
        for(int sat=0; sat<4; sat++) {
            for(int les=0; les<4; les++) {
                if(dp[B+1][sat][les] == 0) continue;
                // printf("dp[%d][%d][%d] = %d\n", B+1, sat, les, dp[B+1][sat][les]);
                int lim_x = (les >> 0 & 1 ? 1 : (N >> B & 1));
                int lim_y = (les >> 1 & 1 ? 1 : (N >> B & 1));
                for(int x=0; x<lim_x + 1; x++) {
                    for(int y=0; y<lim_y + 1; y++) {
                        int b1 = (x == 1 && y == 0);
                        int b2 = (x == 1 && y == 1);
                        int les1 = (les >> 0 & 1) || x < lim_x;
                        int les2 = (les >> 1 & 1) || y < lim_y;
                        if(!(sat >> 0 & 1) && b2) continue;
                        if(!(sat >> 0 & 1) && x == 0 && y == 1) continue;
                        
                        int nsat = sat | (b1 << 0) | (b2 << 1);
                        int nles = les | (les1 << 0) | (les2 << 1);
                        // printf("update: (%d, %d, %d) <= (%d, %d, %d)\n", B, nsat, nles, B+1, sat, les);
                        (dp[B][nsat][nles] += dp[B+1][sat][les]) %= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i=0; i<4; i++) (ans += dp[0][3][i]) %= MOD;
    printf("%d\n", ans);
    return 0;
}
0