結果
問題 | No.434 占い |
ユーザー |
![]() |
提出日時 | 2016-10-19 18:03:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 1,908 bytes |
コンパイル時間 | 1,307 ms |
コンパイル使用メモリ | 159,848 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 16:52:02 |
合計ジャッジ時間 | 2,673 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d", &T); | ~~~~~^~~~~~~~~~ main.cpp:48:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%s", S); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) using ll = long long; using P = std::tuple<int,int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; char S[100100]; int inv[100100]; template <typename T> T expt(T a, T n, T mod = std::numeric_limits<T>::max()){ T res = 1; while(n){ if(n & 1){res = res * a % mod;} a = a * a % mod; n >>= 1; } return res; } int main(){ //* std::cin.tie(nullptr); std::ios::sync_with_stdio(false); /*/ /*/ for(int i=1;i<=100000;++i){ // generate inv if(i == 1 || i % 3 == 0){inv[i] = 1;} else{ inv[i] = expt(i % 9, 5, 9); } } int T; scanf("%d", &T); for(int _=0;_<T;++_){ scanf("%s", S); int l = strlen(S), n = l - 1; if(count(S, S+l, '0') == l){ std::cout << 0 << std::endl; continue; } int three_n = 0, m = 1; int res = 0; for(int i=0;i<=n;++i){ if(i >= 1){ int x = i; while(x % 3 == 0){ --three_n; x /= 3; } m = m * inv[x] % 9; x = n - i + 1; while(x % 3 == 0){ ++three_n; x /= 3; } m = m * x % 9; } int a = S[i] - '0', three_n2 = three_n + (a % 3 == 0) + (a % 9 == 0); if(three_n2 < 2){ res = (res + a * m % 9 * expt(3, three_n) % 9) % 9; } // std::cout << a << ", " << three_n2 << ", " << res << std::endl; } std::cout << (res > 0 ? res : 9) << std::endl; } }