結果

問題 No.505 カードの数式2
ユーザー fura
提出日時 2020-05-31 01:09:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,023 ms / 2,000 ms
コード長 565 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 203,884 KB
最終ジャッジ日時 2025-01-10 19:45:33
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         int n,a[16]; scanf("%d",&n);
      |                      ~~~~~^~~~~~~~~
main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         rep(i,n) scanf("%d",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n,a[16]; scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);

	vector<vector<lint>> L(n);
	L[0]={a[0]};
	rep(i,n-1){
		for(lint x:L[i]){
			L[i+1].emplace_back(x+a[i+1]);
			L[i+1].emplace_back(x-a[i+1]);
			L[i+1].emplace_back(x*a[i+1]);
			if(a[i+1]!=0) L[i+1].emplace_back(x/a[i+1]);
		}
		sort(L[i+1].begin(),L[i+1].end());
		L[i+1].erase(unique(L[i+1].begin(),L[i+1].end()),L[i+1].end());
	}
	printf("%lld\n",L[n-1].back());

	return 0;
}
0