답안 #216892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216892 2020-03-28T10:07:48 Z jzh Tower Defense (CEOI19_towerdefense) C++14
25 / 100
5 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
    cin>>sx>>sy>>ex>>ey>>d;
    vector<pair<ll,ll> >v;
    if (sy>ey||(sy==ey&&sx>ex)){
        swap(sy,ey);
        swap(sx,ex);
    }
    d-=abs(sy-ey)+abs(sx-ex);
    if (d==0){
        cout<<"0\n";
        return 0;
    }
    else if (d<0){
        cout<<"impossible\n";
        return 0;
    }
    if (sy+1==ey&&sx+1==ex){
        /*
        E. 
        .H
        */
        
        if (d<4||d%2==1){
            cout<<"impossible\n";
            return 0;
        }
        d-=4;
        x1=sx+1;
        y1=sy;
        v.push_back({x1,y1});
        x2=sx;
        y2=sy+1;
        v.push_back({x2,y2});
        d/=2;
        while (d--){
            y1--;
            x2--;
            v.push_back({x1,y1});
            v.push_back({x2,y2});
        }
    }
    else if (sy+1==ey&&sx-1==ex){
        /*
        .E 
        H.
        */
        if (d<4||d%2==1){
            cout<<"impossible\n";
            return 0;
        }
        d-=4;
        x1=sx-1;
        y1=sy;
        v.push_back({x1,y1});
        x2=sx;
        y2=sy+1;
        v.push_back({x2,y2});
        d/=2;
        while (d--){
            y1--;
            x2++;
            v.push_back({x1,y1});
            v.push_back({x2,y2});
        }
    }
    else if (sx==ex){//vertical line
        //Assume d>0 
        if (d<2||d%2==1){
            cout<<"impossible\n";
            return 0;
        }
        v.push_back({sx,sy+1});
        d-=2;
        x1=sx;
        y1=sy+1;
        x2=sx;
        y2=sy+1;
        d/=2;
        while (d--){
            x1++;
            x2--;
            v.push_back({x1,y1});
            v.push_back({x2,y2});
        }
    }
    else if (sy==ey){//horizontal line
        //Assume d>0 
        if (d<2||d%2==1){
            cout<<"impossible\n";
            return 0;
        }
        v.push_back({sx+1,sy});
        d-=2;
        x1=sx+1;
        y1=sy;
        x2=sx+1;
        y2=sy;
        d/=2;
        while (d--){
            y1++;
            y2--;
            v.push_back({x1,y1});
            v.push_back({x2,y2});
        }
    }
    else if (ex>sx){
        /*
        E.
        ..
        .H
        */
        if (ex-sx==1||ey-sy==1)d-=2;
        else d-=4;
        if (d<0||d%2==1){
            cout<<"impossible\n";
            return 0;
        }
        d/=2;
        v.push_back({sx+1,sy});
        v.push_back({sx,sy+1});
        x1=sx;
        y1=sy+1;
        x2=sx+1;
        y2=sy;
        if (d!=0){
            if (ex-sx==1){
                v.push_back({sx-1,sy+1});
                d--;
                x1=sx-1;
            }
            if (ey-sy==1){
                y2=sy-1;
                d--;
                v.push_back({sx+1,sy-1});
            }
        }
        while (d--){
                x1--;
                y2--;
                v.push_back({x1,y1});
                v.push_back({x2,y2});
        }

    }
    else if (sx>ex){
        /*
        .E
        ..
        H.
        */
        if (sx-ex==1||ey-sy==1)d-=2;
        else d-=4;
        if (d<0||d%2==1){
            cout<<"impossible\n";
            return 0;
        }
        d/=2;
        v.push_back({sx-1,sy});
        v.push_back({sx,sy+1});
        x1=sx;
        y1=sy+1;
        x2=sx-1;
        y2=sy;
        if (d!=0){
            if (sx-ex==1){
                v.push_back({sx+1,sy+1});
                x1=sx+1;
                d--;
            }
            if (ey-sy==1){
                y2=sy-1;
                d--;
                v.push_back({sx-1,sy-1});
            }
            
        }
        while (d--){
            x1++;
            y2--;
            v.push_back({x1,y1});
            v.push_back({x2,y2});
        }
        

    }
    else cout<<"Error\n";
    
    
    cout<<v.size()<<'\n';
    for (i=0;i<v.size();i++){
        cout<<v[i].first<<' '<<v[i].second<<'\n';
    }
}

Compilation message

towerdefense.cpp: In function 'int main()':
towerdefense.cpp:196:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v.size();i++){
              ~^~~~~~~~~
towerdefense.cpp:7:22: warning: unused variable 'i1' [-Wunused-variable]
     ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
                      ^~
towerdefense.cpp:7:39: warning: unused variable 'a' [-Wunused-variable]
     ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
                                       ^
towerdefense.cpp:7:41: warning: unused variable 'b' [-Wunused-variable]
     ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
                                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 392 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Incorrect 4 ms 256 KB Expected but did not find "impossible".
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 392 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Incorrect 4 ms 256 KB Expected but did not find "impossible".
22 Halted 0 ms 0 KB -