結果
| 問題 |
No.443 GCD of Permutation
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-01-30 22:18:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 608 bytes |
| コンパイル時間 | 2,081 ms |
| コンパイル使用メモリ | 191,816 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-01-30 22:18:04 |
| 合計ジャッジ時間 | 3,651 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%s",s+1);
| ~~~~~^~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
#define FL(i,a,b) for(ll i=(a);i<=(b);i++)
#define FR(i,a,b) for(ll i=(a);i>=(b);i--)
#define ll long long
using namespace std;
const ll MAXN = 1e4 + 10;
char s[MAXN];
ll cnt[10];
signed main(){
scanf("%s",s+1);
ll n=strlen(s+1);
FL(i,1,n) cnt[s[i]-'0']++;
FL(i,0,9) if(cnt[i]==n) printf("%s\n",s+1),exit(0);
ll mx=0;
FL(i,1,9){
if(!cnt[i]) continue;
FL(j,0,i-1){
if(!cnt[j]) continue;
mx=((!mx)?9*(i-j):__gcd(mx,9*(i-j)));
}
}
FR(i,mx,1){
if(mx%i) continue;
ll las=0;
FL(j,1,n) las=((las*10)%i+(ll)(s[j]-'0'))%i;
if(!las) printf("%lld\n",i),exit(0);
}
}
vjudge1