結果

問題 No.505 カードの数式2
コンテスト
ユーザー dnish
提出日時 2017-04-21 23:06:12
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 627 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 996 ms
コンパイル使用メモリ 179,668 KB
実行使用メモリ 186,068 KB
最終ジャッジ日時 2026-04-03 00:48:26
合計ジャッジ時間 1,771 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 1 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i = n; i < (int) N; i++)
#define ck(n,a,b)	((a)<=(n)&&(n)<(b))
#define p(s)		cout<<(s)<<endl
typedef long long ll;
const int inf=1e9;
using namespace std;

int main() {
	int N;
	cin>>N;
	int a[16];
	int ans=0;
	int minus=0;
	int mnx=-10;
	int m=-1;
	REP(i,0,N) 	{
		cin>>a[i];
		if(a[i]<0){
			if(mnx<a[i]){
				mnx=a[i];
				m=i;
			}
			minus++;
		}
	}
	REP(i,0,N){
		if(a[i]==0){
			continue;
		}else if(a[i]==1){
			ans++;
		}else if(m==i&&(minus%2)){
			ans-=a[i];
		}
		else{
			if(ans==0){
				ans+=a[i];
			}
			else	ans*=a[i];
		}
		p(ans);
	}
	p(ans);
	return 0;
}
0