結果

問題 No.2300 Substring OR Sum
ユーザー InTheBloom
提出日時 2023-05-12 23:26:04
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 994 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 211,516 KB
実行使用メモリ 63,916 KB
最終ジャッジ日時 2024-06-22 17:57:01
合計ジャッジ時間 14,631 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 13 OLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N = readln.split[0].to!(int);
    int[] A;
    {
        int[] buf = readln.split.to!(int[]);
        foreach (_; 0..N) {
            A = buf;
        }
    }

    solve(N, A);
}

void solve (int N, int[] A) {
    const int digits = 28;
    int[][] cumsum = new int[][](A.length + 1, digits);

    // bit$BN_@QOB(B
    foreach (idx, a; A) {
        foreach (x; 0..digits) {
            cumsum[idx + 1][x] = cumsum[idx][x];
        }
        for (int i = 0; 0 < a; i++) {
            cumsum[idx + 1][i] += a % 2;
            a /= 2;
        }
    }

    long ans = 0;

    foreach (i; 0..N) {
        int[] power = new int[](digits);
        foreach (x; 0..digits - 1) {
            power[x] = cumsum[N][x] - cumsum[i][x];
        }

        int radix = 2;
        int base = 1;
        foreach (how; power) {
            ans += how * base;
            base *= radix;
        }
    }
    foreach (x; cumsum) {
        writeln(x);
    }

    writeln(ans);
}
0