#include #include using namespace std; using namespace atcoder; #define vvv(name, d, h, w, type, init) \ std::vector>> name((d), \ std::vector>((h), std::vector((w), (init)))) #define all(v) v.begin(),v.end() vector f1 = {0, -1, 0, 1}, f2 = {-1, 0, 1, 0}; #define PB push_back #define mannhattan(x1, x2, y1, y2) (abs(x1 - x2) + abs(y1 - y2)) // マンハッタン距離 = |x1-x2|+|y1-y2| #define rep(i, n) for (int i = 0; i < (int)(n); i++) # pragma GCC target("avx2") # pragma GCC optimize("O3") # pragma GCC optimize("unroll-loops") #define vv(name, h, w, type, init) \ std::vector> name((h), std::vector((w), (init))) #define vc_cout(v) \ do \ { \ int nn = v.size(); \ for (int i = 0; i < nn; i++) \ { \ cout << v[i] << " "; \ } \ cout << endl; \ } while (0) template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } namespace inversion_impl { using S = long long; S op(S a, S b) { return a + b; } S e() { return 0; } } /** * @brief 転倒数(Inversion Number)を求める関数 * * @tparam T 配列の要素型 * @param q 0 ~ n-1 の順列(または値の範囲が 0 <= x < n である要素数nの配列) * @return long long 転倒数 */ template long long inversion_permutation(const std::vector& q) { int n = static_cast(q.size()); if (n <= 1) return 0; // 区間和を管理する Point Add Range Sum セグメント木 atcoder::segtree seg(n); long long inversions = 0; for (int i = 0; i < n; ++i) { int val = static_cast(q[i]); // cerr< inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } bool bfs_est(int xx1, int yy1, int hhh, int www) { return (0 <= xx1 && xx1 < hhh && 0 <= yy1 && www > yy1); } using pll = pair; #define en cerr << "------------" << endl namespace Timer{ /* @FplusFplusF */ chrono::steady_clock::time_point program_start,start; void program_start_snap(){//int mainのすぐそばに置く program_start=start=chrono::steady_clock::now(); //Timer::program_start_snap();とおく } void snap(){//時間を、今にリセット start=chrono::steady_clock::now(); } int get_ms(){//snap,program_start_snapのどっちかを読んでからの経過時間 auto now=chrono::steady_clock::now(); int ms=chrono::duration_cast(now-start).count(); return ms; } int get_ms_all_program(){//program_start_snap() を呼んでからのプログラム全体の経過時間 auto now=chrono::steady_clock::now(); int ms=chrono::duration_cast(now-program_start).count(); return ms; } } mt19937 mt; uint32_t rand_int(uint32_t r){ //[0,r) assert(r!=0); return ((uint64_t)mt()*r)>>32; } int rand_int(int l,int r){ //[l,r) assert(l &ss){ return m * (m - 1) / 2 - inversion_permutation(ss); } void solve(){ Timer::program_start_snap(); cin>>n; vector a(m); rep(i,m){ cin>>a[i]; a[i]--; } state s; s.init(); vvv(dp,n,n,4,int,0); vectorb(m); rep(i,m){ //地点iからスタート auto [x,y] = pointer(i); S dire = dir(i); int _ = 0; while(1){ // cout< save_b = b; rep(i,m){ //地点iからスタート auto [x,y] = pointer(i); S dire = dir(i); int _ = 0; while(1){ // cout<