結果

問題 No.1765 While Shining
ユーザー gazellegazelle
提出日時 2021-11-26 22:31:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 202,192 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-12 05:10:58
合計ジャッジ時間 3,550 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i, n, m) for(long long i = (n); i < (long long)(m); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr ld eps = 1e-6;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
    REP(i, v.size()) {
        if(i)
            os << " ";
        os << v[i];
    }
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    ll ans = 0;
    vector<vector<int>> lasts(2, vector<int>(2, n - 1));
    for(int i = n - 1; i >= 0; i--) {
        lasts[i % 2][a[i]] = i;
        ans += min(lasts[i % 2][0], lasts[!(i % 2)][1]) - i;
    }
    cout << ans << endl;
    return 0;
}
0