結果

問題 No.2748 Strange Clock
ユーザー Yu_212Yu_212
提出日時 2024-04-21 14:58:41
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,590 bytes
コンパイル時間 3,291 ms
コンパイル使用メモリ 258,696 KB
実行使用メモリ 177,920 KB
最終ジャッジ日時 2024-10-13 13:47:09
合計ジャッジ時間 10,229 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,496 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 1 ms
5,248 KB
testcase_11 AC 1 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 3 ms
5,248 KB
testcase_15 AC 2 ms
5,248 KB
testcase_16 AC 4 ms
5,248 KB
testcase_17 AC 5 ms
5,248 KB
testcase_18 AC 10 ms
5,248 KB
testcase_19 AC 9 ms
5,248 KB
testcase_20 AC 28 ms
7,680 KB
testcase_21 AC 30 ms
7,808 KB
testcase_22 AC 120 ms
18,432 KB
testcase_23 AC 120 ms
18,432 KB
testcase_24 AC 487 ms
42,112 KB
testcase_25 AC 472 ms
42,112 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
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;
using pll = pair<ll, ll>;
const ll mod = 998244353;
int n;

ll extgcd(ll a, ll b) {
  ll x0 = 1, x1 = 0, y0 = 0, y1 = 1;
  while (b != 0) {
    ll q = a / b;
    ll r = a % b;
    ll x2 = x0 - q * x1;
    ll y2 = y0 - q * y1;
    a = b;
    b = r;
    x0 = x1;
    x1 = x2;
    y0 = y1;
    y1 = y2;
  }
  return x0;
}

ll crt(ll r1, ll m1, ll r2, ll m2, ll dpq1) {
  ll m = m1 * m2;
  ll temp = (r2 - r1) * dpq1 % m2;
  return ((r1 + m1 * temp) % m + m) % m;
}


constexpr ll pw(ll a, ll b) {
  ll x = 1;
  while (b > 0) {
    if ((b & 1) == 1) {
      x = x * a;
    }
    a = a * a;
    b >>= 1;
  }
  return x;
}

const ll m1_15 = pw(3, 15);
const ll m2_15 = pw(4, 15);
const ll p6_15 = pw(6, 15);
const ll p12_15 = pw(12, 15);
const ll dpq1_15 = extgcd(m1_15, m2_15);
const ll m_15 = m1_15 * m2_15;
ll crt_15(ll r1, ll r2) {
  ll temp = (r2 - r1) * dpq1_15 % m2_15;
  return ((r1 + m1_15 * temp) % m_15 + m_15) % m_15;
}


constexpr int N15 = 15;
void main15() {
  ll m;
  cin >> m;
  m += 2;
  map<ll, vector<ll>> mp;
  for (ll v3 = 0; v3 < m1_15; v3 += 3) {
    ll v4 = 0;
    ll v6 = 0;
    ll tmp = v3;
    ll pc4 = 4;
    ll pc6 = 6;
    for (int i = 1; i < n; i++) {
      tmp /= 3;
      v4 += tmp % 3 * pc4;
      v6 += tmp % 3 * pc6;
      pc4 *= 4;
      pc6 *= 6;
    }
    ll v12 = crt_15(v3, v4);
    ll diff = (v12 % p6_15 + p6_15 - v6) % p6_15;
    mp[diff].push_back(v12);
  }
  ll ans = 0;
  for (auto &[k, vv]: mp) {
    sort(vv.begin(), vv.end());
    ll last = vv[vv.size() - 1] - p12_15;
    for (ll v : vv) {
      if (v - m > last) {
        ans++;
      }
      last = v;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0)->sync_with_stdio(false);
  cin >> n;
  if (n == 15) {
    main15();
    return 0;
  }
  ll m;
  cin >> m;
  m += 2;
  ll p3 = pw(3, n);
  ll p4 = pw(4, n);
  ll p6 = pw(6, n);
  ll p12 = pw(12, n);
  ll dpq1 = extgcd(p3, p4);
  map<ll, vector<ll>> mp;
  for (ll v3 = 0; v3 < p3; v3 += 3) {
    ll v4 = 0;
    ll v6 = 0;
    ll tmp = v3;
    ll pc4 = 4;
    ll pc6 = 6;
    for (int i = 1; i < n; i++) {
      tmp /= 3;
      v4 += tmp % 3 * pc4;
      v6 += tmp % 3 * pc6;
      pc4 *= 4;
      pc6 *= 6;
    }
    ll v12 = crt(v3, p3, v4, p4, dpq1);
    ll diff = (v12 % p6 + p6 - v6) % p6;
    mp[diff].push_back(v12);
  }
  ll ans = 0;
  for (auto &[k, vv]: mp) {
    sort(vv.begin(), vv.end());
    ll last = vv[vv.size() - 1] - p12;
    for (ll v : vv) {
      if (v - m > last) {
        ans++;
      }
      last = v;
    }
  }
  cout << ans << endl;
}
0