結果
| 問題 |
No.1505 Zero-Product Ranges
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-28 12:49:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 652 bytes |
| コンパイル時間 | 1,615 ms |
| コンパイル使用メモリ | 172,388 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-25 16:19:05 |
| 合計ジャッジ時間 | 5,085 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 35 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
27 | for(auto [i,j] : p){
| ^
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<n; ++i)
#define repl(i,m,n) for(ll i=m; i<n; ++i)
int main(){
int N;
cin >> N;
vector<int> A(N);
for(int &a : A) cin >> a;
vector<pair<int,int>> p;
int pre = A[0], cnt = 0;
rep(i, 0, N){
if(A[i] == pre) cnt++;
else{
p.push_back({pre, cnt});
pre = A[i];
cnt = 1;
}
}
p.push_back({pre, cnt});
ll ans = N*(N+1)/2;
for(auto [i,j] : p){
if(i == 1){
ans -= ll(j*(j+1)/2);
}
}
cout << ans << endl;
return 0;
}