CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Ruudukko
Sender:Lieska
Submission time:2020-11-08 18:48:45 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:6:31: error: 'int y1' redeclared as different kind of symbol
 int n, m, yes=0, t[3030], x1, y1, x2, y2, valmis;
                               ^~
In file included from /usr/include/features.h:424:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from input/code.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:221:1: note: previous declaration 'double y1(double)'
 __MATHCALL (y1,, (_Mdouble_));
 ^
input/code.cpp: In function 'int main()':
input/code.cpp:85:9: error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'double(double) noexcept')
     cin >> y1 >> x1 >> y2 >> x2;
     ~~~~^~~~~
In file included from /usr/include/c++/7/sstream:38:0,
                 from /...

Code

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

#define PB push_back

int n, m, yes=0, t[3030], x1, y1, x2, y2, valmis;
vector<int> ans[3030], r[3030];

void poista(int a, int b){
    int c=ans[a][0], d=ans[a][1];
    ans[a].pop_back();
    ans[a].pop_back();
    if (c!=b) ans[a].PB(c);
    else ans[a].PB(d);

    c=ans[b][0], d=ans[b][1];
    ans[b].pop_back();
    ans[b].pop_back();
    if (c!=a) ans[b].PB(c);
    else ans[b].PB(d);
}

void lisaa2(int a, int b){
    ans[a].PB(b);
    ans[b].PB(a);
}

void lisaa4(int a, int b, int c, int d){
    lisaa2(a, b);
    lisaa2(b, c);
    lisaa2(c, d);
}

void lisaa6(int a, int b, int c, int d, int e, int f){
    lisaa4(a, b, c, d);
    lisaa2(d, e);
    lisaa2(e, f);
}

void lisaa8(int a, int b, int c, int d, int e, int f, int g, int h){
    lisaa6(a, b, c, d, e, f);
    lisaa2(f, g);
    lisaa2(g, h);
}

void lisaa10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j){
    lisaa8(a, b, c, d, e, f, g, h);
    lisaa2(h, i);
    lisaa2(i, j);
}

void f(int a, int edel, int k){
    //cout << a << " " << edel << " " << k << " " << valmis <<  "\n";
    if (yes) return;
    if (t[a]==-1){
        if (k==valmis) {
            ans[edel].PB(a);
            ans[a].PB(edel);
            yes=1;
        }
        return;
    }
    if (t[a] || yes) return;
    t[a]=1;
    ans[edel].PB(a);
    ans[a].PB(edel);
    for (auto u:r[a]){
        if (u!=edel){
            f(u, a, k+1);
        }
    }
    if (yes==0){
        ans[edel].pop_back();
        ans[a].pop_back();
    }
    t[a]=0;
    return;
}


int main(){
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    cin >> n >> m;
    cin >> y1 >> x1 >> y2 >> x2;
    if (x2<x1){
        swap(x2, x1);
        swap(y1, y2);
    }
    set<int> s;
    s.insert(x1);
    if (x1>1){
        s.insert(x1-1);
        if ((x1-1)%2==0) s.insert(x1-2);
    }
    if (x2>x1){
        s.insert(x2);
        if ((x2-x1)>1){
            s.insert(x1+1);
            if ((x2-x1)%2==1) s.insert(x1+2);
        }
    }
    if (x2<m){
        s.insert(x2+1);
        if ((m-x2)%2==0) s.insert(x2+2);
    }
    while (s.size()<7){
        int a=1;
        while (s.count(a)==1) a++;
        if (a<m){
            s.insert(a);
            s.insert(a+1);
        }
        else break;
    }
    vector<int> v;
    for (auto u:s) v.PB(u);
    for (int i=0; i<v.size(); ++i){
        //cout << i << " " << v[i] << " hei\n";
        for (int j=1; j<=n; ++j){
            int a=(j-1)*m + v[i];
            if (j!=1){
                r[a].PB((j-2)*m + v[i]);
            }
            if (j!=n){
                r[a].PB(j*m + v[i]);
            }
            if (i!=0){
                r[a].PB((j-1)*m + v[i-1]);
            }
            if (i!=(v.size()-1)){
                r[a].PB((j-1)*m + v[i+1]);
            }
        }
    }
    valmis=v.size()*n;
    /*
    for (int i=1; i<=n; ++i){
        for (int j=1; j<=m; ++j){
            for (auto u:r[(i-1)*m+j]) cout << i << " " << j << " " << u << "\n";
        }
    }
    */
    t[(y2-1)*m + x2]=-1;
    f((y1-1)*m+x1, 0, 1);
    if (yes==0){
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
    /*
    for (int i=1; i<=n; ++i){
        for (int j=1; j<=m; ++j){
            for (auto u:ans[(i-1)*m+j]) cout << i << " " << j << " " << u << "\n";
        }
    }
    */

    if (n>1){
        for (int i=v[0]; i>=3; i-=2){
            poista(i, i+m);
            if (n==2){
                lisaa6(i, i-1, i-2, i-2+m, i-1+m, i+m);
            }
            if (n==3){
                lisaa8(i, i-1, i-2, i-2+m, i-2+2*m, i-1+2*m, i-1+m, i+m);
            }
            if (n==4){
                lisaa10(i, i-1, i-2, i-2+m, i-2+2*m, i-2+3*m, i-1+3*m, i-1+2*m, i-1+m, i+m);
            }
        }

        for (int i=v[v.size()-1]; i<=m-2; i+=2){
            poista(i, i+m);
            if (n==2){
                lisaa6(i, i+1, i+2, i+2+m, i+1+m, i+m);
            }
            if (n==3){
                lisaa8(i, i+1, i+2, i+2+m, i+2+2*m, i+1+2*m, i+1+m, i+m);
            }
            if (n==4){
                lisaa10(i, i+1, i+2, i+2+m, i+2+2*m, i+2+3*m, i+1+3*m, i+1+2*m, i+1+m, i+m);
            }
        }
    }
    int a=0;
    while (v[a]<=x1) a++;
    while (a<v.size() && v[a]==(v[a-1]+1)) a++;
    if (a!=v.size() && v[a]<=x2){
        for (int i=v[a-1]; i<=v[a]-3; i+=2){
            if (n==1){
                poista(i, v[a]);
                lisaa4(i, i+1, i+2, v[a]);
            }
            if (n==2){
                if (ans[i][0]==v[a] || ans[i][1]==v[a]){
                    poista(i, v[a]);
                    lisaa6(i, i+1, i+1+m, i+2+m, i+2, v[a]);
                }
                else{
                    poista(i+m, v[a]+m);
                    lisaa6(i+m, i+1+m, i+1, i+2, i+2+m, v[a]+m);
                }
            }
            if (n==3){
                if (ans[i+m][0]==(v[a]+m) || ans[i+m][1]==(v[a]+m)){
                    poista(i, v[a]);
                    lisaa4(i, i+1, i+2, v[a]);
                    poista(i+m, v[a]+m);
                    lisaa4(i+m, i+1+m, i+2+m, v[a]+m);
                    poista(i+2*m, v[a]+2*m);
                    lisaa4(i+2*m, i+1+2*m, i+2+2*m, v[a]+2*m);
                }
                else{
                    if (ans[i][0]==v[a] || ans[i][1]==v[a]){
                        poista(i, v[a]);
                        lisaa8(i, i+1, i+1+m, i+1+2*m, i+2+2*m, i+2+m, i+2, v[a]);
                    }
                    else{
                        poista(i+2*m, v[a]+2*m);
                        lisaa8(i+2*m, i+1+2*m, i+1+m, i+1, i+2, i+2+m, i+2+2*m, v[a]+2*m);
                    }
                }
            }
        }
    }

    a=(y1-1)*m+x1;
    int edel=0;
    while (true){
        int b=0;
        if (ans[a][0]!=edel) b=ans[a][0];
        else b=ans[a][1];
        if (b==(a+1)) cout << 'R';
        if (b==(a-1)) cout << 'L';
        if (b==(a+m)) cout << 'D';
        if (b==(a-m)) cout << 'U';
        if (b==(y2-1)*m+x2) break;
        edel=a;
        a=b;
    }
}