結果

問題 No.1840 Random Painting
ユーザー hitonanode
提出日時 2021-12-31 01:27:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 437 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 77,824 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 15:58:05
合計ジャッジ時間 2,032 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);

    int N;
    string S;
    cin >> N >> S;

    long long ret = 0;
    long long last0 = -1;
    for (long long i = 1; i < N; ++i) {
        if (S[i] == '0') {
            ret += i * (N - i);
            if (last0 >= 0) ret -= last0 * (N - i);

            last0 = i;
        }
    }
    cout << ret << endl;
}
0