結果

問題 No.2748 Strange Clock
ユーザー hiikunZhiikunZ
提出日時 2024-04-20 17:06:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,090 bytes
コンパイル時間 4,233 ms
コンパイル使用メモリ 259,100 KB
実行使用メモリ 335,816 KB
最終ジャッジ日時 2024-04-20 17:06:42
合計ジャッジ時間 17,617 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 21 ms
5,756 KB
testcase_17 AC 21 ms
5,748 KB
testcase_18 AC 79 ms
9,976 KB
testcase_19 AC 79 ms
9,980 KB
testcase_20 AC 272 ms
23,340 KB
testcase_21 AC 270 ms
23,592 KB
testcase_22 AC 1,073 ms
65,156 KB
testcase_23 AC 1,050 ms
65,160 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 481 ms
163,452 KB
testcase_27 AC 446 ms
163,320 KB
testcase_28 AC 1,447 ms
335,692 KB
testcase_29 AC 1,476 ms
335,816 KB
testcase_30 WA -
testcase_31 AC 145 ms
44,316 KB
testcase_32 AC 121 ms
44,432 KB
testcase_33 AC 453 ms
163,320 KB
testcase_34 WA -
testcase_35 AC 1,510 ms
335,692 KB
testcase_36 AC 1,433 ms
335,696 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#include<atcoder/math>
using namespace atcoder;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
constexpr ll MAX = 2000000000000000000;
constexpr ld PI = 3.14159265358979;
constexpr ll MOD = 0;//2024948111;
ld dotorad(ld K){ return PI * K / 180.0; }
ld radtodo(ld K){ return K * 180.0 / PI; }
mt19937 mt;
void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); }
__int128_t modinv(__int128_t A,__int128_t M){
    //A*r+B*n=gcd(A,B)
    A %= M;
    if(A == 0 || __gcd(A,M) != 1){
        //cout << "Error modinv(" << A << "," << M << ")" << endl;
        return -1;
    }
    __int128_t B = M,U = 1,V = 0;
    while(B){
        __int128_t T = A / B;
        A -= T * B;
        swap(A,B);
        U -= T * V;
        swap(U,V);
    }
    U %= M;
    if(U < 0) U += M;
    return U;
}
int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> pow3(60,1),pow4(60,1),pow6(60,1),pow2(60,1);
    for(ll i = 1;i < 60;i++){
        pow2[i] = pow2[i - 1] * 2;
        pow3[i] = pow3[i - 1] * 3;
        pow4[i] = pow4[i - 1] * 4;
        pow6[i] = pow6[i - 1] * 6;
    }
    ll l = pow2[N * 2] * pow3[N];

    if(N >= 13){
        __int128_t t1 = (modinv(pow3[N],pow2[N * 2]) * pow3[N]) % l;
        __int128_t t2 = (modinv(pow2[N * 2],pow3[N]) * pow2[N * 2]) % l;
        ll ID = 0;
        vector<ll> memo2(pow3[N - 1],0);
        for(ll bb = 0;bb < pow3[N];bb += 3){
            ll c = bb;
            ll p4 = 0,p6 = 0;
            for(ll i = 0;i < N;i++){
                ll x = c % 3;
                c /= 3;
                p4 += x * pow4[i];
                p6 += x * pow6[i];
            }
            ll x = (bb * t2 + p4 * t1) % l;
            ll zurasi = p6 - x;
            zurasi %= pow6[N];
            if(zurasi < 0) zurasi += pow6[N];
            memo2[bb / 3] = (zurasi);
        }
        gp_hash_table<ll,ll> X;

        ll ans = 0;
        for(ll id = 0;id < pow3[N - 1];id++){
            ll bb = 3 * id;
            ll z = memo2[id];
            if(X.find(z) != X.end()){
                ll z1 = X[z];
                ll z2 = bb;
                if(z2 < z1) swap(z1,z2);
                ll d1 = (l + z2 - z1 - 3) % l;
                if(d1 >= M) ans++;
                ll d2 = (l + l + z1 - z2 - 3) % l;
                if(d2 >= M) ans++;

                X.erase(z);
                continue;
            }
            else{
                X[z] = bb;
            }
        }
        for(auto [z,bb] : X){
            if(M <= l - 3) ans++;
        }

        cout << ans << endl;
    }
    else{
        map<ll,vector<ll>> A,B;
        vector<ll> Z;
        for(ll bb = 0;bb < pow3[N];bb++){
            ll c = bb;
            ll p3 = 0,p4 = 0,p6 = 0;
            for(ll i = 0;i < N;i++){
                ll x = c % 3;
                c /= 3;
                p3 += x * pow3[i];
                p4 += x * pow4[i];
                p6 += x * pow6[i];
            }
            tuple<ll,ll> P = crt({p3,p4},{pow3[N],pow4[N]});
            ll x = get<0>(P),m = get<1>(P);
            ll zurasi = p6 - x;
            zurasi %= pow6[N];
            if(zurasi < 0) zurasi += pow6[N];
            Z.emplace_back(zurasi);
            //assert(m == l);
            A[zurasi].emplace_back(x);
            A[zurasi].emplace_back(x + l);
            A[zurasi].emplace_back(x + l + l);

            x -= M;
            x %= l;
            if(x < 0) x += l;
            B[zurasi].emplace_back(x);
        }
        sort(Z.begin(),Z.end());
        Z.erase(unique(Z.begin(),Z.end()),Z.end());
        ll ans = 0;
        for(ll z : Z){
            vector<ll> a = A[z],b = B[z];
            sort(a.begin(),a.end());
            sort(b.begin(),b.end());
            for(ll i = 0;i < b.size();i++){
                ll x = b[i];
                auto it = lower_bound(a.begin(),a.end(),x);
                if(*it == x + M) ans++;
            }
        }
        cout << ans << endl;
    }
}
0