結果
問題 | No.1505 Zero-Product Ranges |
ユーザー | Manuel1024 |
提出日時 | 2021-05-14 22:59:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 493 bytes |
コンパイル時間 | 785 ms |
コンパイル使用メモリ | 69,500 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-02 03:34:51 |
合計ジャッジ時間 | 3,141 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <iostream> #include <vector> using namespace std; int main(){ int n; cin >> n; vector<int> a(n); for(auto &p: a) cin >> p; vector<int> memo(n, -1); if(a[n-1] == 0) memo[n-1] = n-1; for(int i = n-2; i >= 0; i--){ memo[i] = memo[i+1]; if(a[i] == 0) memo[i] = i; } long long int ans = 0; for(int i = 0; i < n; i++){ if(memo[i] != -1){ ans += n-memo[i]; } } cout << ans << endl; return 0; }