Submission #339355

# Submission time Handle Problem Language Result Execution time Memory
339355 2020-12-25T05:52:59 Z beksultan04 Riddick's Cube (IZhO13_riddicks) C++14
0 / 100
1122 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-15
const int N = 1e5+12,INF=1e9+7;
int n,m;
map <vector <vector <int> >  ,int> mp;
deque <pair <bool, vector <vector <int> > > >q;

inline bool is_row(vector <vector <int> > &v){
    int i,j;
    for (i=0;i<v.size();++i){
        for (j=1;j<v[i].size();++j){
            if (v[i][j] != v[i][j-1])ret 0;
        }
    }
    ret 1;
}
inline bool is_columm(vector <vector <int> >&v){
    int i,j;
    for (i=1;i<v.size();++i){
        for (j=0;j<v[i].size();++j){
            if (v[i][j] != v[i-1][j])ret 0;
        }
    }
    ret 1;
}


inline void fun1 (vector <int> &v){
    vector <int> p;
    for (int j=0;j<m;++j){
        p.pb(v[j]);
    }
    for (int j=0;j<m;++j){
        v[j] = p[(j+1)%m];
    }
}

inline void fun2 (vector <int> &v){
    vector <int> p;
    for (int j=0;j<m;++j){
        p.pb(v[j]);
    }
    for (int j=0;j<m;++j){
        v[j] = p[((j-1)+m)%m];
    }
}

inline void fun3 (pair <bool,vector <vector <int> >> &v,int &j){
    vector <int> p;
    for (int i=0;i<n;++i){
        p.pb(v.sc[i][j]);
    }
    for (int i=0;i<n;++i){
        v.sc[i][j] = p[((i+1)+n)%n];
    }
}

inline void fun4(pair <bool,vector <vector <int> >> &v,int &j){
    vector <int> p;
    for (int i=0;i<n;++i){
        p.pb(v.sc[i][j]);
    }
    for (int i=0;i<n;++i){
        v.sc[i][j] = p[((i-1)+n)%n];
    }
}


main(){
    vector <vector <int > >v;
    cin>>n>>m;
    v.resize(n);
    int i,j;
    for (i=0;i<n;++i){
        v[i].resize(m);
        for (j=0;j<m;++j){
            cin>>v[i][j];
        }
    }

    mp[v]=1;
    q.pb({0,v});
    while (!q.empty()){
        pair <bool,vector <vector <int> >> t = q[0];
        q.pop_front();
        if (mp[t.sc] == 100500)break;
        if (is_row(t.sc) || is_columm(t.sc)){
            cout <<mp[t.sc]-1;
            ret 0;
        }
        if (t.fr == 0){
            for (i=0;i<m;++i){
                {
                    int c = mp[t.sc];
                    fun3(t,i);
                    if (!mp[t.sc]){
                        mp[t.sc] = c+1;
                        q.pb(t);
                    }
                }
                {
                    int c = mp[t.sc];
                    fun4(t,i);
                    if (!mp[t.sc]){
                        mp[t.sc] = c+1;
                        q.pb(t);
                    }
                }
            }
        }
        for (i=0;i<t.sc.size();++i){
            {
                int c = mp[t.sc];
                bool s = t.fr;
                fun1(t.sc[i]);
                t.fr = 1;
                if (!mp[t.sc]){
                    mp[t.sc] = c+1;
                    q.pb(t);
                }
                t.fr = s;
                fun2(t.sc[i]);

            }
            {
                int c = mp[t.sc];
                bool s = t.fr;
                fun2(t.sc[i]);
                t.fr = 1;
                if (!mp[t.sc]){
                    mp[t.sc] = c+1;
                    q.pb(t);
                }
                t.fr = s;
                fun1(t.sc[i]);
            }
        }

    }
    cout <<100500;
}






Compilation message

riddicks.cpp: In function 'bool is_row(std::vector<std::vector<int> >&)':
riddicks.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (i=0;i<v.size();++i){
      |              ~^~~~~~~~~
riddicks.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (j=1;j<v[i].size();++j){
      |                  ~^~~~~~~~~~~~
riddicks.cpp: In function 'bool is_columm(std::vector<std::vector<int> >&)':
riddicks.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (i=1;i<v.size();++i){
      |              ~^~~~~~~~~
riddicks.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (j=0;j<v[i].size();++j){
      |                  ~^~~~~~~~~~~~
riddicks.cpp: At global scope:
riddicks.cpp:86:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   86 | main(){
      |      ^
riddicks.cpp: In function 'int main()':
riddicks.cpp:128:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |         for (i=0;i<t.sc.size();++i){
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 31 ms 3052 KB Output is correct
10 Correct 33 ms 3052 KB Output is correct
11 Correct 8 ms 1132 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 75 ms 6380 KB Output is correct
14 Correct 671 ms 41452 KB Output is correct
15 Correct 236 ms 16364 KB Output is correct
16 Correct 236 ms 17260 KB Output is correct
17 Correct 68 ms 6380 KB Output is correct
18 Runtime error 1122 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Halted 0 ms 0 KB -