結果

問題 No.505 カードの数式2
ユーザー myantamyanta
提出日時 2017-04-21 23:44:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 28,108 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 02:03:10
合計ジャッジ時間 1,503 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>


typedef long long ll;


void max_u(ll& d, ll v)
{
	if(d<v) d=v;
}


void min_u(ll& d, ll v)
{
	if(d>v) d=v;
}


void pz_u(ll& d, ll v)
{
	if(v>=0 && llabs(d)>v) d=v;
}


void nz_u(ll& d, ll v)
{
	if(v<=0 && llabs(d)>v) d=v;
}


int main(void)
{
	int n, a[16];
	int i, j, k;
	ll result[4], nresult[4], t[4];
	void (*f[4])(ll&, ll)={max_u, min_u, nz_u, pz_u};

	while(scanf("%d", &n)==1)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d", &a[i]);
		}
		for(i=0;i<4;i++)
		{
			result[i]=a[0];
		}

		for(i=1;i<n;i++)
		{
			for(k=0;k<4;k++)
			{
				for(j=0;j<4;j++)
				{
					t[j]=result[k];
				}
				t[0]+=a[i];
				t[1]-=a[i];
				t[2]*=a[i];
				if(a[i]) t[3]/=a[i];

				if(k==0)
				{
					for(j=0;j<4;j++) nresult[j]=t[0];
				}
				for(j=0;j<4;j++)
				{
					for(int l=0;l<4;l++)
					f[j](nresult[j], t[l]);
				}
			}
			for(j=0;j<4;j++) result[j]=nresult[j];
		}
		printf("%lld\n", result[0]);
	}

	return 0;
}
0