結果

問題 No.443 GCD of Permutation
ユーザー azaa414
提出日時 2025-01-25 16:23:05
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,472 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 137,060 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2025-01-25 16:23:25
合計ジャッジ時間 5,776 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:13: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   49 |     for (rl i = 1; i * i <= t; ++i)
      |             ^

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <set>
using namespace std;
#define ll long long
#define ri register int
#define rl register long long
#define mst(x,y) memset(x, y, sizeof(x))
#define ciallo putchar('\n')
#define ilv inline void
#define ili inline int
#define ilb inline bool
#define ill inline long long
constexpr auto N = 1000010;
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}
string str;
vector<ll> b;
bool check(ll x)
{
    ll temp = 0;
    for (auto i : str)
        temp = (temp * 10 + i - '0') % x;
    return temp;
}
int main()
{
    /*freopen("gcd.in", "r", stdin);
    freopen("gcd.out", "w", stdout);*/

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> str;
    set<ll> temp(str.begin(), str.end());
    if (temp.size() == 1) { cout << str; return 0; }
    ll t = 0;
    for (auto i : str)
        for (auto j : str)
            if (i < j) t = gcd(t, 9ll * (j - i));
    for (rl i = 1; i * i <= t; ++i)
    {
        if (!(t % i))
        {
            b.push_back(i);
            if (i != t / i)
                b.push_back(t / i);
        }
    }
    sort(b.rbegin(), b.rend());
    for (auto i : b)
    {
        if (!check(i))
        {
            cout << i;
            return 0;
        }
    }

    /*fclose(stdin);
    fclose(stdout);*/
    return 0;
}
0