結果
問題 |
No.1083 余りの余り
|
ユーザー |
![]() |
提出日時 | 2022-01-22 16:10:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 3,000 ms |
コード長 | 641 bytes |
コンパイル時間 | 667 ms |
コンパイル使用メモリ | 73,056 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-27 13:46:56 |
合計ジャッジ時間 | 2,191 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
//後から大きな値で余りを取っても要素の値は変化しない。 //値を降順に並べた列のsubseqだけを試せばOK(ただし最小値は必ず使う) #include <iostream> #include <algorithm> #include <functional> using namespace std; int n, K; int a[20]; signed main() { int i, j; cin >> n >> K; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, greater<int>()); int ans = 0; for (i = 0; i < (1 << n); i++) { if ((i >> (n - 1)) % 2 == 0) continue; int x = K; for (j = 0; j < n; j++) { if ((i >> j) % 2) { x %= a[j]; } } ans = max(ans, x); } cout << ans << endl; return 0; }