結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2025-01-26 11:19:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 844 bytes |
コンパイル時間 | 1,745 ms |
コンパイル使用メモリ | 158,760 KB |
実行使用メモリ | 13,696 KB |
最終ジャッジ日時 | 2025-01-26 11:20:02 |
合計ジャッジ時間 | 37,356 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 WA * 1 TLE * 17 |
ソースコード
#include<bits/stdc++.h> //#define int long long using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-48;ch=getchar();} return x*f; } void write(int x) { if(x<0)putchar('-'),x=-x; if(x<10)putchar(x+'0'); else write(x/10),putchar(x%10+'0'); } const int N=5e5; const int mod=1e9+7; long long n; int top; int sum[N]; int ans; bool fl[N]; void dfs(int u,int sm){ if(u==top+1){ if(!ans)ans=sm; else ans=__gcd(ans,sm); return; } for(int i=1;i<=top;i++){ if(fl[i])continue; fl[i]=1; dfs(u+1,sm*10+sum[i]); fl[i]=0; } } signed main(){ // freopen("gcd.in","r",stdin); // freopen("gcd.out","w",stdout); cin>>n; while(n){ sum[++top]=n%10; n/=10; } dfs(1,0); cout<<ans<<"\n"; return 0; }