QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#573 | #350773 | #8330. Count off 3 | hos_lyric | hos_lyric | Failed. | 2024-03-11 04:11:51 | 2024-03-11 04:11:51 |
詳細信息
Extra Test:
Accepted
time: 172ms
memory: 17284kb
input:
10 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
124194923 124194923 124194923 124194923 124194923 124194923 124194923 124194923 124194923 124194923
result:
ok 10 numbers
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#350773 | #8330. Count off 3 | hos_lyric | AC ✓ | 68ms | 17396kb | C++14 | 6.4kb | 2024-03-11 03:58:55 | 2024-10-13 18:47:12 |
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#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")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 1000000007;
using Mint = ModInt<MO>;
#define rep4(a) for (int a = 0; a < 4; ++a)
#define rep5(a) for (int a = 0; a < 5; ++a)
#define rep7(a) for (int a = 0; a < 7; ++a)
inline int add(int a, int b) { return ((a += b) >= 7) ? (a - 7) : a; }
inline int red(int a) { return min(a, 7 - a); }
constexpr int PW2[] = {1, 2, 4, 1, 2, 4};
constexpr int PW3[] = {1, 3, 2, 6, 4, 5};
constexpr int LIM = 10004;
/*
at even/odd degree
values at 1,2,3
*/
Mint dp[2][5010][7][7][7];
int SLen;
char S[10010];
int main() {
for (int h = 0; h < 2; ++h) {
dp[h][0][0][0][0] = 1;
for (int i = 0; i < LIM/2; ++i) {
if (2 * i + h != 0) {
memcpy(dp[h][i + 1], dp[h][i], sizeof(dp[h][i]));
}
const int p2 = PW2[(2 * i + h) % 6];
const int p3 = PW3[(2 * i + h) % 6];
rep7(a1) rep7(a2) rep7(a3) {
dp[h][i + 1][add(a1, 1)][add(a2, p2)][add(a3, p3)] += dp[h][i][a1][a2][a3];
}
}
}
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%s", S);
SLen = strlen(S);
reverse(S, S + SLen);
Mint ans = 0;
int now[2][4] = {};
for (int i = SLen; --i >= 0; ) if (S[i] == '1') {
if (i != 0) {
// smaller here
// 4 for wildcard
Mint f[2][5][5][5] = {};
for (int h = 0; h < 2; ++h) {
const int ii = (i + 1 - h) / 2;
rep7(a1) rep7(a2) rep7(a3) {
f[h]
[red(add(a1, now[h][1]))]
[red(add(a2, now[h][2]))]
[red(add(a3, now[h][3]))]
+= dp[h][ii][a1][a2][a3];
}
rep4(a1) rep5(a2) rep5(a3) f[h][4][a2][a3] += f[h][a1][a2][a3];
rep5(a1) rep4(a2) rep5(a3) f[h][a1][4][a3] += f[h][a1][a2][a3];
rep5(a1) rep5(a2) rep4(a3) f[h][a1][a2][4] += f[h][a1][a2][a3];
}
// PIE
Mint here = 0;
rep5(a1) rep5(a2) rep5(a3) {
const Mint t = f[0][a1][a2][a3] * f[1][a1][a2][a3];
(((a1 < 4) + (a2 < 4) + (a3 < 4)) & 1) ? (here -= t) : (here += t);
}
// cerr<<i<<": here = "<<here<<endl;
ans += here;
}
now[i & 1][1] = add(now[i & 1][1], 1);
now[i & 1][2] = add(now[i & 1][2], PW2[i % 6]);
now[i & 1][3] = add(now[i & 1][3], PW3[i % 6]);
}
if (S[0] == '1') {
bool ok = true;
for (int x = 1; x <= 3; ++x) {
ok = ok && (now[0][x] != now[1][x]);
ok = ok && (now[0][x] + now[1][x] != 7);
}
if (ok) {
ans += 1;
}
}
printf("%u\n", ans.x);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}