結果
| 問題 |
No.1083 余りの余り
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-19 21:36:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 3,000 ms |
| コード長 | 546 bytes |
| コンパイル時間 | 2,477 ms |
| コンパイル使用メモリ | 197,120 KB |
| 最終ジャッジ日時 | 2025-01-11 05:53:24 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | int x; scanf("%d%d",&n,&x);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:25:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | rep(i,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int n;
vector<int> a;
int dfs(int S,int x){
if(S==(1<<n)-1) return x;
int S2=S;
rep(i,n) if((S>>i&1)==0 && x<a[i]) S2|=1<<i;
if(S2!=S) return dfs(S2,x);
int res=0;
rep(i,n) if((S>>i&1)==0) res=max(res,dfs(S|1<<i,x%a[i]));
return res;
}
int main(){
int x; scanf("%d%d",&n,&x);
a.resize(n);
rep(i,n) scanf("%d",&a[i]);
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
n=a.size();
printf("%d\n",dfs(0,x));
return 0;
}