結果
問題 | No.2956 Substitute with Average |
ユーザー |
![]() |
提出日時 | 2024-12-12 10:54:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,073 bytes |
コンパイル時間 | 3,772 ms |
コンパイル使用メモリ | 276,896 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-12 10:54:11 |
合計ジャッジ時間 | 5,962 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 WA * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define rep(i, n) for (int i = 0; i < (int)(n); i++)typedef vector<int> VI;typedef vector<VI> VVI;typedef vector<long long> VL;typedef vector<VL> VVL;typedef long long LL;#define all(a) (a).begin(), (a).end()#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl#define ALL(a) (a).begin(),(a).end()#define pb push_backint main() {int n;cin>>n;int AA[n];rep(i,n){cin>>AA[i];}LL ans=LL(n)*(n+1)/2;for(int i=1;i<=30;i++){//cout<<i<<endl;VI A,B;int a=0,b=0,sum=0;rep(j,n){//cout<<A[j]<<endl;if(AA[j]==i){if(sum!=0){if(b==sum*i){B.pb(1);}else{B.pb(0);}b=0;sum=0;}a++;}else{if(a!=0){A.pb(a);a=0;}b+=AA[j];sum++;}//cout<<b<<endl;}if(a!=0){A.pb(a);}int m=A.size();//cout<<m<<' '<<B.size()<<endl;rep(i,m){ans-=LL(A[i])*(A[i]+1)/2;}rep(i,m-1){if(B[i]){ans-=LL(A[i])*A[i+1];}}}ans++;cout<<ans<<endl;}