結果
問題 | No.2748 Strange Clock |
ユーザー | Rubikun |
提出日時 | 2024-12-27 05:05:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,430 ms / 2,000 ms |
コード長 | 5,535 bytes |
コンパイル時間 | 2,605 ms |
コンパイル使用メモリ | 219,552 KB |
実行使用メモリ | 77,952 KB |
最終ジャッジ日時 | 2024-12-27 05:06:07 |
合計ジャッジ時間 | 13,305 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 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 | 2 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 3 ms
5,248 KB |
testcase_17 | AC | 3 ms
5,248 KB |
testcase_18 | AC | 6 ms
5,248 KB |
testcase_19 | AC | 7 ms
5,248 KB |
testcase_20 | AC | 16 ms
5,248 KB |
testcase_21 | AC | 16 ms
5,248 KB |
testcase_22 | AC | 45 ms
6,016 KB |
testcase_23 | AC | 49 ms
6,016 KB |
testcase_24 | AC | 140 ms
11,520 KB |
testcase_25 | AC | 142 ms
11,520 KB |
testcase_26 | AC | 442 ms
28,112 KB |
testcase_27 | AC | 418 ms
28,132 KB |
testcase_28 | AC | 1,401 ms
77,948 KB |
testcase_29 | AC | 1,430 ms
77,788 KB |
testcase_30 | AC | 155 ms
11,588 KB |
testcase_31 | AC | 140 ms
11,528 KB |
testcase_32 | AC | 146 ms
11,520 KB |
testcase_33 | AC | 421 ms
28,160 KB |
testcase_34 | AC | 1,404 ms
77,952 KB |
testcase_35 | AC | 1,397 ms
77,824 KB |
testcase_36 | AC | 1,402 ms
77,948 KB |
testcase_37 | AC | 1 ms
5,248 KB |
testcase_38 | AC | 3 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define vi vector<int> #define vl vector<ll> #define vii vector<pair<int,int>> #define vll vector<pair<ll,ll>> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define vvii vector<vector<pair<int,int>>> #define vvll vector<vector<pair<ll,ll>>> #define vst vector<string> #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define all(x) (x).begin(),(x).end() #define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end()) #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=300005,INF=15<<26; // crt + floor_sum //https://github.com/atcoder/ac-library/releases/tag/v1.4 constexpr long long safe_mod(long long x, long long m) { x %= m; if (x < 0) x += m; return x; } constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) { a = safe_mod(a, b); if (a == 0) return {b, 0}; long long s = b, t = a; long long m0 = 0, m1 = 1; while (t) { long long u = s / t; s -= t * u; m0 -= m1 * u; auto tmp = s; s = t; t = tmp; tmp = m0; m0 = m1; m1 = tmp; } if (m0 < 0) m0 += b / s; return {s, m0}; } std::pair<long long, long long> crt(const std::vector<long long>& r, const std::vector<long long>& m) { assert(r.size() == m.size()); int n = int(r.size()); long long r0 = 0, m0 = 1; for (int i = 0; i < n; i++) { assert(1 <= m[i]); long long r1 = safe_mod(r[i], m[i]), m1 = m[i]; if (m0 < m1) { std::swap(r0, r1); std::swap(m0, m1); } if (m0 % m1 == 0) { if (r0 % m1 != r1) return {0, 0}; continue; } long long g, im; std::tie(g, im) = inv_gcd(m0, m1); long long u1 = (m1 / g); if ((r1 - r0) % g) return {0, 0}; long long x = (r1 - r0) / g % u1 * im % u1; r0 += x * m0; m0 *= u1; if (r0 < 0) r0 += m0; } return {r0, m0}; } unsigned long long floor_sum_unsigned(unsigned long long n, unsigned long long m, unsigned long long a, unsigned long long b) { unsigned long long ans = 0; while (true) { if (a >= m) { ans += n * (n - 1) / 2 * (a / m); a %= m; } if (b >= m) { ans += n * (b / m); b %= m; } unsigned long long y_max = a * n + b; if (y_max < m) break; n = (unsigned long long)(y_max / m); b = (unsigned long long)(y_max % m); std::swap(m, a); } return ans; } long long floor_sum(long long n, long long m, long long a, long long b) { assert(0 <= n && n < (1LL << 32)); assert(1 <= m && m < (1LL << 32)); unsigned long long ans = 0; if (a < 0) { unsigned long long a2 = safe_mod(a, m); ans -= 1ULL * n * (n - 1) / 2 * ((a2 - a) / m); a = a2; } if (b < 0) { unsigned long long b2 = safe_mod(b, m); ans -= 1ULL * n * ((b2 - b) / m); b = b2; } return ans + floor_sum_unsigned(n, m, a, b); } ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } ll keta=3; string f3(ll x){ string res; for(ll q=0;q<keta;q++){ res+=char('0'+(x%3)); x/=3; } reverse(all(res)); return res; } string f4(ll x){ string res; for(ll q=0;q<keta;q++){ res+=char('0'+(x%4)); x/=4; } reverse(all(res)); return res; } string f6(ll x){ string res; for(ll q=0;q<keta;q++){ res+=char('0'+(x%6)); x/=6; } reverse(all(res)); return res; } ll g3(string S){ ll res=0; for(char c:S){ res*=3; res+=(c-'0'); } return res; } ll g4(string S){ ll res=0; for(char c:S){ res*=4; res+=(c-'0'); } return res; } ll g6(string S){ ll res=0; for(char c:S){ res*=6; res+=(c-'0'); } return res; } int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); ll N,M;cin>>N>>M; keta=N; ll b2=(1LL<<N),b3=g3(string(N,'2'))+1,b4=g4(string(N,'3'))+1,b6=g6(string(N,'5'))+1; ll ans=0; set<ll> SE; vll Z(b3/3); vl A(N); for(int i=0;i<N;i++){ string S(N,'0'); S[i]='1'; ll s=g3(S),t=g4(S); auto zz=crt({s,t},{b3,b4}); A[i]=zz.fi; } for(ll s=0;s<b3;s+=3){ string S=f3(s); ll t=g4(S); ll a=0; for(int i=0;i<N;i++){ if(S[i]=='1') a+=A[i]; if(S[i]=='2') a+=A[i]*2; } a%=(b3*b4); ll u=g6(S); Z[s/3]=(mp((a-u+b6)%b6,a)); } sort(all(Z)); int i=0; while(i<si(Z)){ int j=i; while(j<si(Z)&&Z[i].fi==Z[j].fi) j++; for(int k=i+1;k<j;k++){ if(Z[k].se-(Z[k-1].se+2)>M) ans++; } if(Z[i].se-(Z[j-1].se+2)+b3*b4>M) ans++; i=j; } cout<<ans<<endl; }