結果

問題 No.2843 Birthday Present Struggle
ユーザー NachiaNachia
提出日時 2024-08-23 23:13:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,379 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 82,052 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-23 23:13:16
合計ジャッジ時間 2,727 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 1 ms
6,944 KB
testcase_35 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #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;
}
0