結果
| 問題 | No.435 占い(Extra) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-22 19:02:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,844 bytes |
| 記録 | |
| コンパイル時間 | 2,687 ms |
| コンパイル使用メモリ | 181,024 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 12:13:05 |
| 合計ジャッジ時間 | 6,126 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 9 |
ソースコード
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
int in() {
int n, c;
while ((c = getchar()) < '0') if (c == EOF) abort();
n = c - '0';
while ((c = getchar()) >= '0') n = n * 10 + c - '0';
return n;
}
void out(int n) {
int res[11], i = 0;
do { res[i++] = n % 10, n /= 10; } while (n);
while (i) putchar(res[--i] + '0');
putchar('\n');
}
int p2[6], inv[9];
int count(int n) {
int res = 0;
while (n % 3 == 0) n /= 3, res++;
return res;
}
pair<int, int> decomp(int n) {
if (n == 0) return{ 0, 0 };
int three = 0;
while (n % 3 == 0) {
n /= 3;
three++;
}
return{ inv[n % 9], three };
}
int main() {
p2[0] = 1;
for (int i = 1; i < 6; i++) p2[i] = p2[i - 1] * 2 % 9;
for (int i = 0; i < 6; i++) inv[p2[i]] = i;
int T = in();
while (T--) {
int n = in() - 1, x = in(), a = in(), b = in(), m = in();
auto N = decomp(n);
pair<int, int> L(0, 0);
pair<int, int> R = N;
bool zero = true;
int64_t ans = 0;
for (int i = 0; i <= n; i++) {
if (x % 10 != 0) zero = false;
int two = (N.first - L.first - R.first) % 6;
int three = N.second - L.second - R.second;
int c = p2[two] * (three == 0 ? 1 : three == 1 ? 3 : 0);
ans += c * (x % 10);
auto ll = decomp(i + 1);
auto rr = decomp(n - i);
L.first += ll.first;
L.second += ll.second;
R.first -= rr.first;
R.second -= rr.second;
x = ((x ^ a) + b) % m;
}
ans %= 9;
if (ans == 0) ans = 9;
if (zero) ans = 0;
out(ans);
}
}