結果
問題 | No.1765 While Shining |
ユーザー |
|
提出日時 | 2022-08-20 09:37:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,058 bytes |
コンパイル時間 | 2,000 ms |
コンパイル使用メモリ | 197,508 KB |
最終ジャッジ日時 | 2025-01-31 01:56:30 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
typedef long long ll;typedef long double ld;#include <bits/stdc++.h>using namespace std;#define int long longsigned 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;}