結果

問題 No.929 よくあるボールを移動するやつ
ユーザー jnarutojjnarutoj
提出日時 2019-11-22 22:18:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,230 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 81,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-01 12:12:14
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll int n;
	cin>>n;
	ll zc=0,ex=0,ans=0;
	ll a[n];
	rep(i,n)cin>>a[i];
	rep(i,n){
		ans+=zc+ex;
		if(a[i]>1){
			ll d=a[i]-1;
			if(d>zc){ex+=d-zc;zc=0;}
			else zc-=d;
		}
		else if(!a[i]){
			if(ex)ex--;
			else zc++;
		}
	}
	cout<<ans+zc+ex;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}
0