結果

問題 No.3723 Climb or Detour
コンテスト
ユーザー Lemona
提出日時 2026-09-19 14:18:29
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,098 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,846 ms
コンパイル使用メモリ 359,904 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2026-09-19 14:18:48
合計ジャッジ時間 6,867 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for (int i=0; i<(n); ++i)
#define nall(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl

template<typename T,typename U>inline bool chmax(T&a,U b){if(a<b){a=b;return 1;}return 0;}
template<typename T,typename U>inline bool chmin(T&a,U b){if(a>b){a=b;return 1;}return 0;}

using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;

const int inf = (1e9);
const ll INF = (1e18)+(1e9);
const ll dx[] = {0,1,0,-1,1,1,-1,-1};
const ll dy[] = {1,0,-1,0,1,-1,1,-1};

//#include <atcoder/all>
//using namespace atcoder;

//using mint = modint998244353;

int testcase(){
    ll n,k; cin >> n >> k;
    P s,t;
    cin >> s.first >> s.second;
    cin >> t.first >> t.second;
    s.first--;s.second--;
    t.first--;t.second--;
    ll cnt = abs(s.first-t.first)+abs(s.second-t.second);
    if(k<cnt || k>cnt*2 || (k-cnt)%2){
        cout << -1 << endl;
        return 0;
    } 
    vector<vector<ll>> board(n,vector<ll>(n));
    rep(i,n){
        rep(j,n){
            if((i+j)%2) board[i][j] = 1;
        }
    }

    ll base = board[s.first][s.second];
    board[t.first][t.second] = base;

    P now = s;
    ll rem = cnt*2-k;
    while(rem){
        if(abs(now.first-t.first)){
            now.first -= (now.first-t.first)/abs(now.first-t.first);
            if(board[now.first][now.second]!=base){
                board[now.first][now.second] = base;
            }
            rem--;
        }
        else{
            now.second -= (now.second-t.second)/abs(now.second-t.second);
            if(board[now.first][now.second]!=base){
                board[now.first][now.second] = base;
            }
            rem--;
        }
    }
    rep(i,n){
        rep(j,n){
            if(board[i][j]==base) cout << '.';
            else cout << '#';
        }
        cout << endl;
    }
    return 0;
}

int main(){
    ios::sync_with_stdio(false); 
    cin.tie(nullptr);

    //int t=1;
    //cin >> t;
    //while(t--)
    testcase();

    return 0;
}
0