結果
| 問題 | No.434 占い |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-20 10:55:04 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 8 ms / 2,000 ms |
| + 475µs | |
| コード長 | 953 bytes |
| 記録 | |
| コンパイル時間 | 3,241 ms |
| コンパイル使用メモリ | 168,480 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-10-20 10:55:19 |
| 合計ジャッジ時間 | 5,397 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <vector>
void solve() {
using namespace std;
string s;
cin >> s;
int n = s.size() - 1;
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 = s[i] - '0';
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(); }
}