結果

問題 No.2053 12345...
コンテスト
ユーザー Mohamed Magdy
提出日時 2024-03-12 12:51:21
言語 C++14
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 552 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 898 ms
コンパイル使用メモリ 181,096 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-06 07:42:24
合計ジャッジ時間 4,036 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   int n;
   cin >> n;
   vector<int> a(n);
   for (auto &it : a) {
      cin >> it;
   }
   int cnt = 1;
   int curr = a[0];
   ll sum = 0;
   for (int i = 1; i < n; i++) {
      if (a[i] == curr) cnt++;
      else {
         // every subarray is valid add it to the sum
         sum += 1LL * cnt * (cnt + 1) / 2;
         cnt = 1;
      }
   }
   sum += 1LL * cnt * (cnt + 1) / 2;

   cout << sum << "\n";
   
}   
0