結果

問題 No.2748 Strange Clock
ユーザー Nzt3Nzt3
提出日時 2024-04-12 22:56:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,983 bytes
コンパイル時間 2,570 ms
コンパイル使用メモリ 211,676 KB
実行使用メモリ 180,160 KB
最終ジャッジ日時 2024-04-13 02:39:56
合計ジャッジ時間 9,780 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,884 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 9 ms
6,944 KB
testcase_17 AC 9 ms
6,944 KB
testcase_18 AC 32 ms
6,940 KB
testcase_19 AC 31 ms
6,940 KB
testcase_20 AC 98 ms
8,832 KB
testcase_21 AC 99 ms
8,960 KB
testcase_22 AC 344 ms
18,860 KB
testcase_23 AC 339 ms
18,732 KB
testcase_24 AC 1,103 ms
55,836 KB
testcase_25 AC 1,098 ms
55,880 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll ipow(ll a,int n){
  if(n==0)return 1ll;
  if(n%2)return a*ipow(a,n-1);
  ll ret=ipow(a,n/2);
  return ret*ret;
}
array<int,15> ItoTx(ll n,int x,int N){
  array<int,15> ret;
  for(int i=0;i<N;i++){
    ret[i]=(n%x);
    n/=x;
  }
  assert(n==0);
  return ret;
}
ll TtoI(array<int,15> v,int x,int N){
  ll ret=0;
  for(int i=N-1;i>=0;i--){
    ret=ret*x+v[i];
  }
  return ret;
}
namespace Lib {
ll extGCD(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = extGCD(b, a % b, y, x);
  y = y - a / b * x;
  return d;
}
ll modinv(ll a, ll m) {
  ll x = 0, y = 0, d = extGCD(a, m, x, y);
  if (d != 1) {
    return -1;
  }
  return x;
}
}  // namespace Lib
namespace Lib {
pair<ll, ll> crt(array<ll,2> r,array<ll,2> m) {
  ll ret_r = r[0], ret_m = m[0];
  constexpr int n = 2;
  for (int i = 1; i < n; i++) {
    ll x = 0, y = 0, d = extGCD(ret_m, m[i], x, y);
    if ((ret_r - r[i]) % d != 0) {
      return make_pair(-1ll, -1ll);
    }
    ll tmp = x * (r[i] - ret_r) / d % (m[i] / d);
    ret_r += tmp * ret_m;
    ret_m *= m[i] / d;
    ret_r %= ret_m;
    if (ret_r < 0) ret_r += ret_m;
  }
  if (ret_r < 0) ret_r += ret_m;
  return make_pair(ret_r, ret_m);
}
}  // namespace Lib


int main(){
  ll N,M;
  cin>>N>>M;
  ll V_MAX3=ipow(3,N),V_MAX4=ipow(4,N);
  ll p2=ipow(2,N);
  unordered_map<ll,vector<ll>> cnt;
  for(int i=0;i<V_MAX3;i++){
    auto v3=ItoTx(i,3,N);
    // for(int j:v3)cerr<<j;
    // cerr<<'\n';
    ll i3=TtoI(v3,3,N),i4=TtoI(v3,4,N),i6=TtoI(v3,6,N);
    ll d=((((i4-i6)%p2+p2)%p2)<<30)+(((i3-i6)%V_MAX3+V_MAX3)%V_MAX3);
    array<ll,2> r={i3,i4},m={V_MAX3,V_MAX4};
    auto ret=Lib::crt(r,m);
    cnt[d].push_back(ret.first);
  }
  ll ans=0;
  for(auto [i,v]:cnt){
    if(v.empty())continue;
    sort(v.begin(),v.end());
    v.push_back(v[0]+V_MAX3*V_MAX4);
    for(int i=1;i<(int)v.size();i++){
      if(v[i]-v[i-1]>M)ans+=1;
    }
  }
  cout<<ans<<'\n';
}
0