QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#557 | #348188 | #8330. Count off 3 | hos_lyric | ucup-team1198 | Failed. | 2024-03-10 15:14:33 | 2024-03-10 15:14:33 |
Details
Extra Test:
Accepted
time: 1814ms
memory: 6536kb
input:
10 101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
586027236 714385491 276192899 279789873 250133033 219170406 937291086 140512570 309231269 694117998
result:
ok 10 numbers
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#348188 | #8330. Count off 3 | ucup-team1198# | AC ✓ | 1840ms | 6716kb | C++20 | 2.8kb | 2024-03-09 17:23:40 | 2024-10-13 18:46:00 |
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#define ll long long
using namespace std;
int go(int state, int by) {
int n_state = 0;
int pw = 1;
for (int i = 1; i < 7; ++i) {
int cur = state % 7;
state /= 7;
n_state += pw * ((cur * i + by) % 7);
pw *= 7;
}
return n_state;
}
bool good(int state) {
for (int i = 1; i < 7; ++i) {
if (state % 7 == 0) return 0;
state /= 7;
}
return 1;
}
const int ST = 7 * 7 * 7 * 7 * 7 * 7;
int ago[2][ST];
// 117649
ll count_good[2][ST];
const int MOD = 1e9 + 7;
void back(const int i) {
static int counter = 0;
// from i to i - 1;
memset(count_good[1-i], 0, sizeof(count_good[1-i]));
for (int j = 0; j < ST; ++j) {
count_good[1-i][ago[0][j]] += count_good[i][j];
count_good[1-i][ago[1][j]] += count_good[i][j];
}
counter++;
if (counter == 33) {
for (int j = 0; j < ST; ++j) {
count_good[1-i][j] %= MOD;
}
counter = 0;
}
// maybe %;
}
void solve() {
for (int i = 0; i < ST; ++i) {
ago[0][go(i, 0)] = i;
ago[1][go(i, 1)] = i;
}
int t;
cin >> t;
vector<string> s(t);
for (int i = 0; i < t; ++i) {
cin >> s[i];
// s[i] = '1';
// for (int j = 0; j < 9999; ++j) {
// s[i] += '0' + rand() % 2;
// }
}
vector<ll> ans(t, 0);
vector<vector<int>> query(t);
for (int i = 0; i < t; ++i) {
query[i].resize(s[i].size());
int st = 0;
for (int j = 0; j < s[i].size(); ++j) {
if (s[i][j] == '1') {
query[i][s[i].size() - 1 - j] = go(st, 0);
st = go(st, 1);
} else {
query[i][s[i].size() - 1 - j] = -1;
st = go(st, 0);
}
}
ans[i] += (good(st) && s[i].back() == '1');
}
for (int i = 0; i < ST; ++i) {
count_good[1][i] = good(go(i, 1));
}
// back(1);
for (int i = 1; i < 10001; ++i) {
for (int j = 0; j < t; ++j) {
if (i < query[j].size() && query[j][i] != -1) {
ans[j] = (ans[j] + count_good[i % 2][query[j][i]]) % MOD;
}
}
back(i % 2);
}
for (int i = 0; i < t; ++i) {
cout << ans[i] << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}