結果

問題 No.3727 Garden Master
コンテスト
ユーザー akua
提出日時 2026-09-25 22:12:48
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 30 ms / 2,000 ms
+ 5µs
コード長 4,692 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,524 ms
コンパイル使用メモリ 230,272 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2026-09-25 22:12:53
合計ジャッジ時間 5,086 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a); i<(ll)(b); i++)
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;
template<typename T,typename S> bool chmin(T&a,const S& b){
    return a>b?a=b,1:0;
}
template<typename T,typename S> bool chmax(T&a,const S& b){
    return a<b?a=b,1:0;
}
const ll inf=2e18;
#define all(a) (a).begin(),(a).end()
#define arr(a) (a).rbegin(),(a).rend()
using P=pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;

struct UnionFind {
    vector<int> par,siz;
    UnionFind(int n) : par(n,-1),siz(n,1) {}
    int root(int x){
        if(par[x]==-1)return x;
        else return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool unite(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return false;
        if(siz[x]<siz[y])swap(x,y);
        par[y]=x;
        siz[x]+=siz[y];
        return true;
    }
    int size(int x){
        return siz[root(x)];
    }
};
constexpr int mod=998244353;
struct mint{
    int x;
    mint(ll x_=0) :x(x_%mod){
        if(x<0)x+=mod;
    }
    mint operator-(){
        auto res=*this;
        res.x=(x?mod-x:0);
        return res;
    }
    mint& operator+=(mint r){
        if((x+=r.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(mint r){
        if((x-=r.x)<0)x+=mod;
        return *this;
    }
    mint& operator*=(mint r){
        x=1LL*x*r.x%mod;
        return *this;
    }
    mint& operator/=(mint r){
        return *this*=r.inv();
    }
    friend mint operator+(mint a,mint b){
        return a+=b;
    }
    friend mint operator-(mint a,mint b){
        return a-=b;
    }
    friend mint operator*(mint a,mint b){
        return a*=b;
    }
    friend mint operator/(mint a,mint b){
        return a/=b;
    }
    mint inv() const{return pow(mod-2);}
    mint pow(ll b) const{
        mint a=*this,c=1;
        while(b){
            if(b&1)c*=a;
            a*=a;
            b>>=1;
        }
        return c;
    }
};
using vm=vector<mint>;
template<class S, S (*op)(S,S),S (*e)()> struct SegmentTree{
    private:
    int _n,size,log;
    vector<S> dat;
    void update(int k){
        dat[k]=op(dat[2*k],dat[2*k+1]);
    }
    public:
    SegmentTree():SegmentTree(0){}
    SegmentTree(int n):SegmentTree(vector<S>(n,e())){}
    SegmentTree(const vector<S>& v) : _n(int(v.size())){
        log=0;
        while((1<<log)<_n)log++;
        size=1<<log;
        dat=vector<S>(2*size,e());
        for(int i=0; i<_n; i++)dat[size+i]=v[i];
        for(int i=size-1; i>=1; i--){
            update(i);
        }
    }
    void set(int p,S x){
        p+=size;
        dat[p]=x;
        for(int i=1; i<=log; i++)update(p>>i);
    }
    S get(int p) const {return dat[p+size];}
    S prod(int l,int r) const{
        S sml=e(),smr=e();
        l+=size;
        r+=size;
        while(l<r){
            if(l&1)sml=op(sml,dat[l++]);
            if(r&1)smr=op(dat[--r],smr);
            l>>=1;
            r>>=1;
        }
    }
    S all_prod() const {return dat[1];}
};


void solve(int test){
    /*
    int n=3;
    vp p;
    repi(i,1,n+1)repi(j,1,n+1){
        p.push_back(P(i,j));
    }
    sort(all(p));
    do{
        vvi a(n,vi(n));
        vvi b(n,vi(n));
        rep(i,n*n){
            a[i/n][i%n]=p[i].first;
            b[i/n][i%n]=p[i].second;
        }
        int ok=1;
        rep(i,n-1)rep(j,n-1){
            int suma=a[i][j]+a[i][j+1]+a[i+1][j]+a[i+1][j+1];
            int sumb=b[i][j]+b[i][j+1]+b[i+1][j]+b[i+1][j+1];
            if(suma!=sumb)ok=0;
        }
        if(ok){
            rep(i,n){
                rep(j,n)cout<< "(" << " " << a[i][j] << "," << b[i][j] << ")" << " "; 
                cout << endl;
            }
            cout<< endl;
        }
    }while(next_permutation(all(p)));
    */
    int n; cin >> n;
    map<int,vp> mp;
    repi(i,1,n+1)repi(j,1,n+1){
        mp[i-j].push_back(P(i,j));
    }
    vvi a(n,vi(n)),b(n,vi(n));
    int pa=0;
    repi(d,-n,n+1){
        int nd=d;
        if(pa)nd*=-1;
        vp p=mp[nd];
        int cnt=0;
        rep(i,n){
            int j=i-d;
            if(j>=0 && j<n){
                a[i][j]=p[cnt].first;
                b[i][j]=p[cnt].second;
                cnt++;
            }
        }
        pa^=1;
    }
    rep(i,n){
        rep(j,n)cout << a[i][j] << " ";
        cout << endl;
    }
    rep(i,n){
        rep(j,n)cout << b[i][j] << " ";
        cout << endl;
    }





}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t=1; //cin >> t;
    rep(test,t)solve(test);
}


0