結果
問題 |
No.3082 Make Palindromic Multiple(Judge)
|
ユーザー |
👑 |
提出日時 | 2025-03-28 22:43:36 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,570 ms / 3,500 ms |
コード長 | 4,390 bytes |
コンパイル時間 | 2,979 ms |
コンパイル使用メモリ | 236,348 KB |
実行使用メモリ | 11,324 KB |
最終ジャッジ日時 | 2025-04-16 13:12:29 |
合計ジャッジ時間 | 19,239 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 73 |
コンパイルメッセージ
main.cpp: In function ‘__int128 unsigned inUInt128()’: main.cpp:61:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 61 | scanf("%s", buf); | ~~~~~^~~~~~~~~~~ main.cpp: In function ‘__int128 inInt128()’: main.cpp:66:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 66 | scanf("%s", buf); | ~~~~~^~~~~~~~~~~ main.cpp: In function ‘int main()’: main.cpp:175:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 175 | scanf("%s%lld", buf, &T[k]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <chrono> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") #ifndef LIBRA_OTHER_INT128_H_ #define LIBRA_OTHER_INT128_H_ #include <stdio.h> #include <iostream> constexpr unsigned __int128 toUInt128(const char *s) { unsigned __int128 x = 0; for (; *s; ++s) x = x * 10 + (*s - '0'); return x; } constexpr __int128 toInt128(const char *s) { if (*s == '-') return -toInt128(s + 1); __int128 x = 0; for (; *s; ++s) x = x * 10 + (*s - '0'); return x; } unsigned __int128 inUInt128() { static char buf[41]; scanf("%s", buf); return toUInt128(buf); } __int128 inInt128() { static char buf[41]; scanf("%s", buf); return toInt128(buf); } void out(unsigned __int128 x) { static char buf[41]; int len = 0; do { buf[len++] = '0' + static_cast<int>(x % 10); } while (x /= 10); for (int i = len; --i >= 0; ) putchar(buf[i]); } void out(__int128 x) { if (x < 0) { putchar('-'); out(-static_cast<unsigned __int128>(x)); } else { out(static_cast<unsigned __int128>(x)); } } std::ostream &operator<<(std::ostream &os, unsigned __int128 x) { static char buf[41]; int len = 0; do { buf[len++] = '0' + static_cast<int>(x % 10); } while (x /= 10); for (int i = len; --i >= 0; ) os << buf[i]; return os; } std::ostream &operator<<(std::ostream &os, __int128 x) { if (x < 0) { os << '-' << -static_cast<unsigned __int128>(x); } else { os << static_cast<unsigned __int128>(x); } return os; } #endif // LIBRA_OTHER_INT128_H_ #include <chrono> #ifdef LOCAL mt19937_64 rng(58); #else mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #endif using U = unsigned __int128; constexpr U M = (((U)1) << 96) - 3; U add(U a, U b) { return ((a += b) >= M) ? (a - M) : a; } U mul(U a, U b) { static constexpr U MASK = ((U)1 << 72) - 1; U c = 0; for (int i = 0; i < 4; ++i) { c += a * (b & ((1<<24)-1)); //(a <<= 24) %= M; a = (a >> 72) * 3 + ((a & MASK) << 24); b >>= 24; } return c % M; } using Pair = pair<U, pair<U, U>>; Pair mul(Pair f, Pair g) { return Pair(mul(f.first, g.first), make_pair( add(f.second.first, mul(f.first, g.second.first)), add(mul(f.second.second, g.first), g.second.second) )); } Pair power(Pair f, Int e) { Pair g(1, make_pair(0, 0)); for (; ; f = mul(f, f)) { if (e & 1) g = mul(g, f); if (!(e >>= 1)) return g; } } char buf[200'010]; int K; vector<string> S; vector<Int> T; U BASE; Pair solve() { Pair ret(1, make_pair(0, 0)); for (int k = 0; k < K; ++k) { Pair p(1, make_pair(0, 0)); for (const char s : S[k]) { p = mul(p, Pair(BASE, make_pair(s, s))); } p = power(p, T[k]); ret = mul(ret, p); } //cerr<<S<<" "<<T<<": "<<ret<<endl; return ret; } int main() { BASE |= (U)rng(); BASE |= (U)rng() << 64; BASE %= M; cerr<<"M = "<<M<<", BASE = "<<BASE<<endl; for (; ~scanf("%d", &K); ) { S.resize(K); T.resize(K); for (int k = 0; k < K; ++k) { scanf("%s%lld", buf, &T[k]); S[k] = buf; } const Pair res = solve(); puts((res.second.first == res.second.second) ? "Yes" : "No"); } return 0; }