이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
    int x0, y0, x1, y1, d; cin >> x0 >> y0 >> x1 >> y1 >> d;
    if(x0 > x1){
        swap(x0, x1);
        swap(y0, y1);
    }
    int d1 = abs(y1-y0) + x1-x0;
    if((d1 > d) || ((d1^d) & 1) || (d1 == 1 && d > 1) || ((x1-x0) == 1 && abs(y1-y0) == 1 && d == 4)){
        cout << "impossible" << endl;
        exit(0);
    }
    if(d == d1){
        cout << 0 << endl;
        exit(0);
    }
    //a solution exists, start has lower x
    //cases: diff x >= 2, vertical line of turrets
    //diff y >= 2
    //x0+1, y0+-1
    if(x1 > x0+1){
        if(y1 < y0) swap(y0, y1);
        int l = (d-d1-2)/2;
        cout << y1-y0+1+l+l << endl;
        for(int i=y0-l; i <= y1+l; ++i) cout << x0+1 << " " << i << endl;
    }
    else if(abs(y1-y0) > 1){
        int l = (d-d1-2)/2;
        cout << 2*(x1-x0+1+l+l) << endl;
        for(int i=x0-l; i <= x1+l; ++i) cout << i << " " << y0+1 << endl;
        for(int i=x0-l; i <= x1+l; ++i) cout << i << " " << y0-1 << endl;
    }
    else if(y1 > y0){ //{x1, y1} = {x0+1, y0+1}
        int l = (d - 4)/2;
        cout << d-4 << endl;
        for(int i=1; i<=l; ++i) cout << x0+i << " " << y0 << endl << x0 << " " << y0+i << endl;
    }
    else { //{x1, y1} = {x0+1, y0-1}
        int l = (d - 4)/2;
        cout << d-4 << endl;
        for(int i=1; i<=l; ++i) cout << x0+i << " " << y0 << endl << x0 << " " << y0-i << endl;
    }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |