結果
問題 | No.2843 Birthday Present Struggle |
ユーザー |
👑 ![]() |
提出日時 | 2024-08-23 23:13:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 2,379 bytes |
コンパイル時間 | 857 ms |
コンパイル使用メモリ | 79,828 KB |
最終ジャッジ日時 | 2025-02-24 00:16:37 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
// #ifdef NACHIA // #define _GLIBCXX_DEBUG // #else // #define NDEBUG // #endif #include <iostream> #include <string> #include <vector> #include <algorithm> using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<int(n); i++) const i64 INF = 1001001001001001001; template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; } template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; } #include <atcoder/modint> using Modint = atcoder::static_modint<998244353>; #include <iterator> namespace nachia{ struct GridAdj4{ int H; int W; struct GridPos { int y; int x; }; struct GridAdj4Iter{ using value_type = GridPos; using iterator_category = std::forward_iterator_tag; using Me = GridAdj4Iter; int c; int y; int x; int p; static inline const int dy[4] = { -1, 0, 1, 0 }; static inline const int dx[4] = { 0, -1, 0, 1 }; static Me Beg(int c, int y, int x){ Me res = Me{c,y,x,4}; return ++res; } Me& operator++(){ p--; while(p >= 0 && !((c >> p) & 1)) p--; return *this; } Me operator++(int){ auto q=*this; return ++q; } bool operator==(const Me& r) const { return p == r.p; } bool operator!=(const Me& r) const { return p != r.p; } GridPos operator*() const { return GridPos{ y+dy[p], x+dx[p] }; } }; struct GridAdj4Range{ int c; int y; int x; GridAdj4Iter begin() const { return GridAdj4Iter::Beg(c,y,x); } GridAdj4Iter end() const { return GridAdj4Iter{c,y,x,-1}; } }; GridAdj4(int height, int width) : H(height), W(width) {} GridAdj4Range operator()(int y, int x) const { GridAdj4Range res = {0,y,x}; if(0 < y) res.c |= 1; if(0 < x) res.c |= 2; if(y < H-1) res.c |= 4; if(x < W-1) res.c |= 8; return res; } }; } // namespace nachia using namespace std; void testcase(){ int N; cin >> N; int X[6]; rep(i,6) cin >> X[i]; auto g = nachia::GridAdj4(N, N); vector<pair<int,int>> ans; for(auto [u,v] : g(X[4]-1,X[5]-1)) ans.push_back({u+1,v+1}); cout << ans.size() << endl; for(auto [u,v] : ans) cout << u << " " << v << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }