結果
| 問題 | No.435 占い(Extra) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-20 03:05:40 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 93 ms / 2,000 ms |
| + 460µs | |
| コード長 | 1,011 bytes |
| 記録 | |
| コンパイル時間 | 1,117 ms |
| コンパイル使用メモリ | 171,228 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-10-20 03:06:14 |
| 合計ジャッジ時間 | 5,229 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge6_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <vector>
void solve() {
using namespace std;
int n, x, a, b, m;
cin >> n >> x >> a >> b >> m;
n--;
constexpr int inv[] = {0, 1, 5, 0, 7, 2, 0, 4, 8};
bool all_zero = true;
int ans = 0, comb = 1, e = 0;
for (int i = 0; i <= n; i++) {
int c = x % 10;
x ^= a;
x += b;
x %= m;
all_zero &= (c == 0);
if (e == 0) { ans += c * comb; }
if (e == 1) { ans += c * comb * 3; }
ans %= 9;
if (i == n) { break; }
int k = n - i;
while (k % 3 == 0) {
k /= 3;
e++;
}
comb *= k;
k = i + 1;
while (k % 3 == 0) {
k /= 3;
e--;
}
comb *= inv[k % 9];
comb %= 9;
}
if (!all_zero && ans == 0) { ans = 9; }
cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) { solve(); }
}