結果
問題 | No.2144 MM |
ユーザー |
![]() |
提出日時 | 2022-12-02 23:43:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,721 bytes |
コンパイル時間 | 997 ms |
コンパイル使用メモリ | 110,596 KB |
最終ジャッジ日時 | 2025-02-09 04:30:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘mint test(int, int)’: main.cpp:65:1: warning: no return statement in function returning non-void [-Wreturn-type] 65 | } | ^ main.cpp: In instantiation of ‘void print_vector(std::vector<_Tp>, char) [with T = atcoder::static_modint<998244353>]’: main.cpp:63:21: required from here main.cpp:41:46: error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘__gnu_cxx::__alloc_traits<std::allocator<atcoder::static_modint<998244353> >, atcoder::static_modint<998244353> >::value_type’ {aka ‘atcoder::static_modint<998244353>’}) 41 | for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; | ~~~~~^~~~~ In file included from /usr/include/c++/13/iostream:41, from main.cpp:1: /usr/include/c++/13/ostream:110:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]’ 110 | operator<<(__ostream_type& (*__pf)(__ostream_type&)) | ^~~~~~~~ /usr/include/c++/13/ostream:110:36: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<atcoder::static_modint<998244353> >, atcoder::static_modint<998244353> >::value_type’ {aka ‘atcoder::static_modint<998244353>’} to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)’ {aka ‘std::basic_ostream<char>& (*)(std::basic_ostream<char>&)’} 110 | operator<<(__ostream_type& (*__pf)(__ostream_type&)) | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/ostream:119:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/modint> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll MOD = 998244353; using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } mint test(int n, int m){ auto dp = vec2d(n+1, m, mint(0)); dp[0][0] = 1; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ for(int k = 0; k < m-1; k++){ dp[i+1][(j+k)%m] += dp[i][j]; } } print_vector(dp[i+1]); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m; cin >> n >> m; // test(n, m); vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; int sum = 0; for(int i = 0; i < n; i++){ if(i%2 == 0) sum += a[i]; else sum -= a[i]; sum += m; sum %= m; } if(sum != 0){ cout << -1 << endl; return 0; } mint ans = 1; int x = 0; for(int i = 0; i < n; i++){ // ここで初めて小さくなるパターン if(a[i] > 0){ int rem = n-i-1; if(rem == 0){ continue; } mint tmp; mint offset; if(rem%2 == 0){ mint ave = (mint(m-1).pow(rem)-1)/(m); tmp = ave*a[i]; offset = 1; }else{ mint ave = (mint(m-1).pow(rem)+1)/(m); tmp = ave*a[i]; offset = -1; } int l = 0, r = 0; if(i%2 == 1){ l = x-(a[i]-1); r = x; }else{ l = x; r = x+a[i]-1; } if(i%2 == 0){ l -= (rem/2)*2; r -= (rem/2)*2; }else{ l -= ((rem+1)/2)*2; r -= ((rem+1)/2)*2; } l %= m; r %= m; l = (l+m)%m; r = (r+m)%m; int small_idx = (m-rem)%m; small_idx = (small_idx+m)%m; // cout << l << ' ' << r << ' ' << small_idx << endl; if(r >= l){ if(l <= small_idx && small_idx <= r) { tmp+=offset; } }else{ if(small_idx >= l || small_idx <= r) { tmp+=offset; } } ans += tmp; } if(i%2 == 0) x += a[i]; else x += m-a[i]; x %= m; } cout << ans << endl; }