結果
問題 | No.3069 Invisible Speedrun |
ユーザー |
|
提出日時 | 2025-03-22 09:54:26 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 8,884 bytes |
コンパイル時間 | 3,368 ms |
コンパイル使用メモリ | 137,496 KB |
実行使用メモリ | 26,228 KB |
平均クエリ数 | 586.73 |
最終ジャッジ日時 | 2025-03-22 09:54:36 |
合計ジャッジ時間 | 9,015 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 80 |
ソースコード
#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); for (int i=0; i<n; i++) { cout << "R" << endl; in(int, v); if (v==1) break; cout << "D" << endl; if (v==1) break; } } /********************************************************************************/ #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 vec_int_in(name, size) vector<int> name(size); for(auto &x : name) cin >> x #define vec_ll_in(name, size) vector<long long> name(size); for(auto &x : name) cin >> x #define vec_double_in(name, size) vector<double> name(size); for(auto &x : name) cin >> x #define vec_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 vec2d_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_1(t1, n1) t1##_in(n1) #define in_2(t1, n1, t2, n2) t1##_in(n1); t2##_in(n2) #define in_3(t1, n1, t2, n2, t3, n3) t1##_in(n1); t2##_in(n2); t3##_in(n3) #define in_4(t1, n1, t2, n2, t3, n3, t4, n4) t1##_in(n1); t2##_in(n2); t3##_in(n3); t4##_in(n4) // 可変長引数対応 (修正版) #define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME #define in(...) GET_MACRO(__VA_ARGS__, in_4, in_4, in_3, in_3, in_2, in_2, in_1, in_1)(__VA_ARGS__) // サイズ指定が必要なコンテナ用の特殊マクロ #define vec_in(type, name, size) vec_##type##_in(name, size) #define vec2d_in(type, name, h, w) vec2d_##type##_in(name, h, w) #define pair_in(t1, t2, name) pair_##t1##_##t2##_in(name) 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