結果
問題 |
No.929 よくあるボールを移動するやつ
|
ユーザー |
|
提出日時 | 2025-09-21 01:31:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,096 bytes |
コンパイル時間 | 1,971 ms |
コンパイル使用メモリ | 200,360 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-09-21 01:31:06 |
合計ジャッジ時間 | 3,193 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 WA * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; int n; int a[100001]; long long int res = 0; set <int> S; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for(int i=1;i<=n;i++) cin >> a[i]; for(int i=1;i<=n;i++) { if(a[i] >= 1) S.insert(i); } for(int i=1;i<=n;i++) { if(a[i]==0) { auto it = S.lower_bound(i); int Min = 1e9; int idx = -1; if(it==S.end()) { it--; int d = abs(i - *it); if(Min > d) { Min = d; idx = *it; } } else { int d = abs(i - *it); if(Min > d) { Min = d; idx = *it; } } a[idx]-=1; a[i] += 1; res += Min; if(a[idx]==0) S.erase(idx); } } cout << res << '\n'; return 0; }