結果

問題 No.1765 While Shining
コンテスト
ユーザー Haa
提出日時 2021-11-26 22:31:12
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 827 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 956 ms
コンパイル使用メモリ 182,212 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-19 08:10:32
合計ジャッジ時間 2,325 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    REP(i,n){
        if(i%2==1)
            a[i]=!a[i];
    }
    int x=0;
    ll ans=0;
    for(int i=n-1;i>=0;i--){
        if(i<n-1){
            if(a[i]==a[i+1])
                x++;
            else
                x=1;
        }
        if(i%2!=a[i])
            ans+=x;
    }
    cout << ans << endl;
    return 0;
}
0