結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
myanta
|
| 提出日時 | 2017-04-21 23:44:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 950 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 25,600 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-14 07:19:18 |
| 合計ジャッジ時間 | 1,082 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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;
}
myanta