結果
問題 |
No.505 カードの数式2
|
ユーザー |
![]() |
提出日時 | 2017-04-21 22:46:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 691 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 24,832 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-20 05:36:03 |
合計ジャッジ時間 | 1,168 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 8 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:32:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include<cstdio> #include<cstdlib> typedef long long ll; void abs_u(ll& d, ll v) { if(llabs(d)<llabs(v)) d=v; } void max_u(ll& d, ll v) { if(d<v) d=v; } int main(void) { int n, a[16]; int i, j, last_minus; ll result, t[4]; void (*f)(ll&, ll); while(scanf("%d", &n)==1) { last_minus=0; for(i=0;i<n;i++) { scanf("%d", &a[i]); if(a[i]<0) last_minus=i; } result=a[0]; f=abs_u; for(i=1;i<n;i++) { for(j=0;j<4;j++) t[j]=result; t[0]+=a[i]; t[1]-=a[i]; t[2]*=a[i]; if(a[i]) t[3]/=a[i]; if(i>=last_minus) f=max_u; result=t[0]; f(result, t[1]); f(result, t[2]); f(result, t[3]); } printf("%lld\n", result); } return 0; }