結果
問題 |
No.3070 Collecting Coins Speedrun 2
|
ユーザー |
|
提出日時 | 2025-03-22 10:27:47 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 8,814 bytes |
コンパイル時間 | 1,370 ms |
コンパイル使用メモリ | 141,192 KB |
実行使用メモリ | 7,328 KB |
最終ジャッジ日時 | 2025-03-22 10:27:51 |
合計ジャッジ時間 | 2,767 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <iostream> #include <iomanip> #include <ostream> #include <optional> #include <queue> #include <vector> #include <string> #include <algorithm> #include <numeric> #include <ranges> #include <map> #include <set> using namespace std; #ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ int main() { in(int, n); in(vector_int, a, n); if (n == 1) { cout << 1 << endl; return 0; } int m,p,z; m=p=z=0; for (const auto& a: a) { if (a < 0) m++; else if (a > 0) p++; else z++; } Mint ans = 1; if (m>0) ans *= Mint(2).pow(m - 1); if (p>0) ans *= Mint(2).pow(p - 1); if (m>0 && p>0) ans *= 2; if (z>0) { if (m>0 && p>0) ans *= 3; else ans *= 2; } cout << ans << endl; } /********************************************************************************/ #else #ifdef ONLINE_JUDGE #define debug(x) {} #else const int DEBUG_PRINT = 10; const string bold = "\e[1m"; const string cyan = "\e[36m"; const string red = "\e[31m"; const string reset = "\e[0m"; #define debug(x) {cerr << bold << cyan << "[" << red << __LINE__ << cyan << "] "<< #x << ": " << reset; debgp(x); } template<class T> void debgp(T &x) { cerr << x; } template<class T, class U> void debgp(pair<T,U> &p) { cerr << "("; debgp(p.first); cerr << ", "; debgp(p.second); cerr << ")"; } template<class T> void debgp(vector<T> &v) { cerr << "["; for (int i=0; i<min((int)v.size(), DEBUG_PRINT); i++) { debgp(v[i]); cerr << (i+1!=v.size()?" ":"]\n"); } if (v.size() > DEBUG_PRINT) cerr << " … ]\n"; } template<class T> void debgp(vector<vector<T>> &v) {cerr<<"[\n"; for (int i=0; i<min((int)v.size(), DEBUG_PRINT); i++) { cerr<<" "; debgp(v[i]); } if (v.size() > DEBUG_PRINT) cerr<<" ︙\n"; ; cerr << "]\n"; } #endif using i32 = int; using i64 = long long; const i64 INF = 0x0f0f'0f0f'0f0f'0f0f; template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } vector dx4 = {1, 0, -1, 0}; vector dy4 = {0, 1, 0, -1}; vector dx8 = {1, 1, 0, -1, -1, -1, 0, 1}; vector dy8 = {0, 1, 1, 1, 0, -1, -1, -1}; template<class T, class U> istream& operator>>(istream&i,pair<T,U>&v){ i>>v.first>>v.second; return i; } template<class T> istream& operator>>(istream&i,vector<T>&v){ for(T&e : v) i>>e; return i; } template<class T, class U> ostream& operator<<(ostream &o, pair<T,U> &p){o<<"("<<p.first<<", "<<p.second<<")";return o; } template<class T> ostream& operator<<(ostream&o,vector<T>&v){for(int i=0; i<v.size(); i++) { o << v[i] << (i+1!=v.size()?" ":"\n");} return o;} template<class T> optional<i32> position(vector<T>&v, T x) { auto it = std::find(v.begin(), v.end(), x); if (it == v.end()) return nullopt; return it - v.begin(); } optional<i32> position(string &v, char x) { auto it = std::find(v.begin(), v.end(), x); if (it == v.end()) return nullopt; return it - v.begin(); } template<class T> vector<pair<T, i32>> run_length_encoding(vector<T>&v) { vector<pair<T, i32>> res; if (v.empty()) return res; res.emplace_back(v[0], 0); for (const auto& x : v) { if (res.back().first == x) { res.back().second++; } else { res.emplace_back(x, 1); } } return res; } struct init{init(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}init; // 基本型のマクロ定義 #define int_in(name) int name; cin >> name #define ll_in(name) long long name; cin >> name #define double_in(name) double name; cin >> name #define string_in(name) string name; cin >> name #define char_in(name) char name; cin >> name #define bool_in(name) bool name; cin >> name #define float_in(name) float name; cin >> name // コンテナ型のマクロ定義 #define vector_int_in(name, size) vector<int> name(size); for(auto &x : name) cin >> x #define vector_ll_in(name, size) vector<long long> name(size); for(auto &x : name) cin >> x #define vector_double_in(name, size) vector<double> name(size); for(auto &x : name) cin >> x #define vector_string_in(name, size) vector<string> name(size); for(auto &x : name) cin >> x // ペア型のマクロ定義 #define pair_int_int_in(name) pair<int, int> name; cin >> name.first >> name.second #define pair_ll_ll_in(name) pair<long long, long long> name; cin >> name.first >> name.second // 2次元ベクトルのマクロ定義 #define vector_vector_int_in(name, h, w) vector<vector<int>> name(h, vector<int>(w)); for(int i=0; i<h; i++) for(int j=0; j<w; j++) cin >> name[i][j] // 引数の数に応じた入力マクロ #define in_2(type, name) type##_in(name) #define in_3(type, name, size) type##_in(name, size) #define in_4(type, name, h, w) type##_in(name, h, w) // マクロセレクタ #define GET_IN_MACRO(_1, _2, _3, _4, NAME, ...) NAME #define in(...) GET_IN_MACRO(__VA_ARGS__, in_4, in_3, in_2, UNUSED)(__VA_ARGS__) template<long long MOD> class ModInt { private: long long val; public: ModInt():val(0) {} ModInt(long long x) : val((x % MOD + MOD) % MOD){} ModInt& operator+=(const ModInt& lhr) { val += lhr.val; if (val >= MOD) val -= MOD; return *this; } ModInt& operator-=(const ModInt& lhr) { val -= lhr.val; if (val < 0) val += MOD; return *this; } ModInt& operator*=(const ModInt& lhr) { val *= lhr.val % MOD; val %= MOD; return *this; } ModInt operator-() const { return ModInt(-val); } ModInt operator+(const ModInt& lhr) const { return ModInt(*this) += lhr; } ModInt operator-(const ModInt& lhr) const { return ModInt(*this) -= lhr; } ModInt operator*(const ModInt& lhr) const { return ModInt(*this) *= lhr; } bool operator==(const ModInt& lhr) const { return val == lhr.val; } bool operator!=(const ModInt& lhr) const { return val != lhr.val; } ModInt pow(long long x) const { ModInt res(1); ModInt v(*this); while (x > 0) { if (x & 1) res *= v; v *= v; x >>= 1; } return res; } friend std::ostream& operator<<(std::ostream& os, const ModInt& m) { return os << m.val; } }; using Mint = ModInt<998244353>; #include <vector> #include <stdexcept> template<size_t N, size_t M, class T> class Matrix { private: std::vector<std::vector<T>> mat; public: Matrix() : mat(N, std::vector<T>(M, T())) {} Matrix(const std::vector<std::vector<T>>& v) : mat(v) { if (v.size() != N || (v.size() > 0 && v[0].size() != M)) { throw std::invalid_argument("Input vector dimensions do not match matrix dimensions"); } } // 要素へのアクセス T& operator()(size_t i, size_t j) { return mat[i][j]; } const T& operator()(size_t i, size_t j) const { return mat[i][j]; } // 行列の加算 Matrix operator+(const Matrix& other) const { Matrix result; for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < M; ++j) { result(i, j) = mat[i][j] + other(i, j); } } return result; } // スカラー乗算 Matrix operator*(const T& scalar) const { Matrix result; for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < M; ++j) { result(i, j) = mat[i][j] * scalar; } } return result; } // 行列乗算 template<size_t P> Matrix<N, P, T> operator*(const Matrix<M, P, T>& other) const { Matrix<N, P, T> result; for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < P; ++j) { for (size_t k = 0; k < M; ++k) { result(i, j) += mat[i][k] * other(k, j); } } } return result; } // 単位行列の生成 static Matrix identity() { Matrix result; for (size_t i = 0; i < N; ++i) { result(i, i) = T(1); } return result; } // 行列のべき乗 Matrix pow(long long exponent) const { if (exponent == 0) { return identity(); } if (exponent == 1) { return *this; } Matrix result = identity(); Matrix base = *this; while (exponent > 0) { if (exponent & 1) { result = result * base; } base = base * base; exponent >>= 1; } return result; } // 行列の表示(デバッグ用) void print() const { for (const auto& row : mat) { for (const auto& elem : row) { std::cout << elem << " "; } std::cout << std::endl; } } }; #endif