結果

問題 No.2748 Strange Clock
ユーザー Yu_212Yu_212
提出日時 2024-04-21 14:46:30
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,455 bytes
コンパイル時間 3,248 ms
コンパイル使用メモリ 284,108 KB
実行使用メモリ 175,616 KB
最終ジャッジ日時 2024-04-21 14:46:46
合計ジャッジ時間 10,848 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
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 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 72 ms
8,832 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
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 = extgcd(m1, m2);
  ll m = m1 * m2;
  ll temp = (r2 - r1) * dpq1 % m2;
  return ((r1 + m1 * temp) % m + m) % m;
}


ll conv(ll v, int c) {
  ll r = 0;
  ll pc = 1;
  for (int i = 0; i < n; i++) {
    r += v % 3 * pc;
    pc *= c;
    v /= 3;
  }
  return r;
}

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;
}

int main() {
  cin.tie(0)->sync_with_stdio(false);
  cin >> n;
  ll m;
  cin >> m;
  const ll p3 = pw(3, n);
  const ll p4 = pw(4, n);
  const ll p6 = pw(6, n);
  const ll p12 = pw(12, n);
  unordered_map<ll, vector<ll>> mp;
  for (ll v3 = 0; v3 < p3; v3++) {
    ll v4 = conv(v3, 4);
    ll v6 = conv(v3, 6);
    ll v12 = crt(v3, p3, v4, p4);
    ll diff = (v12 + p6 - v6) % p6;
    mp[diff].push_back(v12);
  }
  ll ans = 0;
  for (auto &[k, vv]: mp) {
    ll last = vv[vv.size() - 1] - p12;
    for (ll v : vv) {
      if (v - m > last) {
        ans++;
      }
      last = v;
    }
  }
  cout << ans << endl;
}
0