結果

問題 No.2748 Strange Clock
ユーザー ponjuiceponjuice
提出日時 2024-04-19 13:38:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,339 bytes
コンパイル時間 2,801 ms
コンパイル使用メモリ 207,108 KB
実行使用メモリ 265,800 KB
最終ジャッジ日時 2024-04-19 13:38:55
合計ジャッジ時間 10,253 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 14 ms
7,500 KB
testcase_21 WA -
testcase_22 AC 39 ms
19,788 KB
testcase_23 AC 41 ms
19,916 KB
testcase_24 WA -
testcase_25 AC 124 ms
36,300 KB
testcase_26 AC 331 ms
134,476 KB
testcase_27 AC 336 ms
134,476 KB
testcase_28 AC 1,033 ms
265,552 KB
testcase_29 WA -
testcase_30 AC 103 ms
36,300 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 330 ms
134,604 KB
testcase_34 AC 1,035 ms
265,800 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 2 ms
5,376 KB
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

ll ll_pow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res *= a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

array<int,15> itoar(ll i) {
    array<int,15>res;
    for(int j = 0; j < 15; j++) {
        res[14 - j] = i % 3;
        i /= 3;
    }
    return res;
}

ll artoi(array<int,15> a, ll e) {
    ll res = 0;
    for(int j = 0; j < 15; j++) {
        res *= e;
        res += a[j];
    }
    return res;
}

pair<ll, ll> extgcd(ll a, ll b) {
    ll s = a, xs = 1, ys = 0, t = b, xt = 0, yt = 1;
    while (true) {
        ll temp = s / t;
        if(temp * t != s)break;
        ll u = s - t * temp;
        ll xu = xs - xt * temp;
        ll yu = ys - yt * temp;

        s = t;
        xs = xt;
        ys = yt;
        t = u;
        xt = xu;
        yt = yu;
    }

    return {xt, yt};
}

ll crt(ll a, ll mod1, ll b, ll mod2) {
    auto [p, q] = extgcd(mod1, mod2);
    ll mod = (mod1 * mod2);
    return ((a + mod1 * ((b - a) * p % mod2)) % mod + mod) % mod;
}

int main(){
    ll n, m;
    cin >> n >> m;

    const ll pow3 = ll_pow(3, n);
    const ll pow4 = ll_pow(4, n);
    const ll pow6 = ll_pow(6, n);
    const ll pow12 = ll_pow(12, n);

    vector<pair<ll,ll>> res;

    for(int i = 0; i < pow3; i += 3) {
        // i
        array<int,15> ret = itoar(i);
        ll i3 = i;
        ll i4 = artoi(ret, 4);
        ll i6 = artoi(ret, 6);

        ll t = crt(i3, pow3, i4, pow4);

        i6 = ((i6 - t) % pow6 + pow6) % pow6;

        res.emplace_back(i6, t);

        // i + 1
        res.emplace_back(i6, t + 1);

        // i + 2
        res.emplace_back(i6, t + 2);
    }

    sort(res.begin(), res.end());
    ll ans = 0;

    ll nw = -1, lt = -1;
    for(int i = 0; i < (int)res.size(); i++) {
        if(nw != res[i].first){
            nw = res[i].first;
            lt = res[i].second + pow12;
        }

        if(i + 1 == res.size() || res[i].first != res[i + 1].first) {
            ans += (lt - res[i].second > m) ? 1 : 0;
        }else{
            ans += (res[i+1].second - res[i].second > m) ? 1 : 0;
        }
    }

    cout << ans << endl;
}
0