結果

問題 No.1765 While Shining
ユーザー erbowlerbowl
提出日時 2022-08-20 09:37:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 197,484 KB
実行使用メモリ 8,580 KB
最終ジャッジ日時 2024-04-17 09:10:00
合計ジャッジ時間 4,402 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 29 ms
6,420 KB
testcase_10 AC 41 ms
7,984 KB
testcase_11 AC 36 ms
7,368 KB
testcase_12 AC 40 ms
7,844 KB
testcase_13 AC 36 ms
7,444 KB
testcase_14 AC 45 ms
8,076 KB
testcase_15 AC 46 ms
8,072 KB
testcase_16 AC 46 ms
8,076 KB
testcase_17 AC 47 ms
7,948 KB
testcase_18 AC 46 ms
8,200 KB
testcase_19 AC 47 ms
8,200 KB
testcase_20 AC 45 ms
8,088 KB
testcase_21 AC 46 ms
8,076 KB
testcase_22 AC 46 ms
8,068 KB
testcase_23 AC 47 ms
8,144 KB
testcase_24 AC 36 ms
8,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ll n;
    std::cin >> n;
    vector<ll> a(n),b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        b[i] = a[i];
        if(i%2==1){
            b[i] = !b[i];
        }
    }
    vector<ll> zi,oi;
    for (int i = 0; i < n; i++) {
        if(b[i]){
            oi.push_back(i);
        }else{
            zi.push_back(i);
        }
        // std::cout << b[i]<<" ";
    }
    // std::cout << std::endl;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if(a[i]==1){
            auto &c = (b[i]? zi : oi);
            // std::cout << "c: "<<c.size() << std::endl;
            auto it = lower_bound(c.begin(),c.end(),i+1);
            if(it==c.end()){
                ans += n-i-1;
            }else{
                // std::cout << i<<" "<<*it << std::endl;
                ans += *it-i;
            }
        }
        // std::cout << ans << std::endl;
    }
    std::cout << ans << std::endl;
}
0