結果
| 問題 |
No.443 GCD of Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-01-25 16:25:32 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 645 bytes |
| コンパイル時間 | 694 ms |
| コンパイル使用メモリ | 82,204 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2025-01-25 16:25:34 |
| 合計ジャッジ時間 | 1,782 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 26 WA * 2 |
ソースコード
#include <iostream>
#include <numeric>
using namespace std;
bool appear[15];
bool factor(string s, int mod) {
int x = 0;
for(char c : s) {
x = x * 10 + (c - '0');
x %= mod;
}
return !x;
}
int main() {
string n;
cin >> n;
for(auto c : n) {
appear[c - '0'] = true;
}
int g = 0;
for(int i = 0; i <= 9; i++) {
for(int j = 0; j < i; j++) {
if(appear[i] and appear[j]) {
g = gcd(g, 9 * (i - j));
}
}
}
for(int i = g; i >= 1; i--) {
if(g % i == 0 and factor(n, i)) {
cout << i;
return 0;
}
}
}