답안 #339327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339327 2020-12-25T05:02:25 Z beksultan04 Riddick's Cube (IZhO13_riddicks) C++14
0 / 100
2000 ms 364 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 <pair <int, vector <vector <int> > > ,int> mp;
deque <pair <int, vector <vector <int> > > >q;

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


pair <int,vector <vector <int> >>fun1 (pair <int,vector <vector <int> >>v,int i){
    vector <int> p;
    for (int j=0;j<m;++j){
        p.pb(v.sc[i][j]);
    }
    for (int j=0;j<m;++j){
        v.sc[i][j] = p[(j+1)%m];
    }
    ret v;
}

pair <int,vector <vector <int> >>fun2 (pair <int,vector <vector <int> >>v,int i){
    vector <int> p;
    for (int j=0;j<m;++j){
        p.pb(v.sc[i][j]);
    }
    for (int j=0;j<m;++j){
        v.sc[i][j] = p[((j-1)+m)%m];
    }
    ret v;
}

pair <int,vector <vector <int> >>fun3 (pair <int,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];
    }
    ret v;
}

pair <int,vector <vector <int> >> fun4(pair <int,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];
    }
    ret v;
}


main(){
    pair <int,vector <vector <int> >>v;
    scan2(n,m)
    v.sc.resize(n);
    int i,j;
    for (i=0;i<n;++i){
        v.sc[i].resize(m);
        for (j=0;j<m;++j){
            scan1(v.sc[i][j])
        }
    }
    v.fr =1;
    mp[v]=1;
    q.pb(v);
    while (!q.empty()){
        pair <int,vector <vector <int> >> t = q[0];
        q.pop_front();
        if (is_row(t) || is_columm(t) || mp[t] -1 == 100500){
            cout <<mp[t]-1;
            ret 0;
        }
        if (t.fr == 1){
            {
                pair <int,vector <vector <int> >> to = fun3(t,i);
                if (!mp[to]){
                    mp[to] = mp[t]+1;
                    q.pb(to);
                }
            }
            {
                pair <int,vector <vector <int> >> to = fun4(t,i);
                if (!mp[to]){
                    mp[to] = mp[t]+1;
                    q.pb(to);
                }
            }
        }
        for (i=0;i<m;++i){
            for (i=0;i<t.sc.size();++i){
                {
                    pair <int,vector <vector <int> >> to = fun1(t,i);
                    to.fr = 2;
                    if (!mp[to]){
                        mp[to] = mp[t]+1;
                        q.pb(to);
                    }
                }
                {
                    pair <int,vector <vector <int> >> to = fun2(t,i);
                    to.fr = 2;
                    if (!mp[to]){
                        mp[to] = mp[t]+1;
                        q.pb(to);
                    }
                }
            }
        }

    }
    cout <<100500;
}






Compilation message

riddicks.cpp: In function 'bool is_row(std::pair<long long int, std::vector<std::vector<long long int> > >)':
riddicks.cpp:27:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (i=0;i<v.sc.size();++i){
      |              ~^~~~~~~~~~~~
riddicks.cpp:28:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (j=1;j<v.sc[i].size();++j){
      |                  ~^~~~~~~~~~~~~~~
riddicks.cpp: In function 'bool is_columm(std::pair<long long int, std::vector<std::vector<long long int> > >)':
riddicks.cpp:36:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (i=1;i<v.sc.size();++i){
      |              ~^~~~~~~~~~~~
riddicks.cpp:37:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (j=0;j<v.sc[i].size();++j){
      |                  ~^~~~~~~~~~~~~~~
riddicks.cpp: At global scope:
riddicks.cpp:90:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   90 | main(){
      |      ^
riddicks.cpp: In function 'int main()':
riddicks.cpp:128:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |             for (i=0;i<t.sc.size();++i){
      |                      ~^~~~~~~~~~~~
riddicks.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
riddicks.cpp:92:5: note: in expansion of macro 'scan2'
   92 |     scan2(n,m)
      |     ^~~~~
riddicks.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
riddicks.cpp:98:13: note: in expansion of macro 'scan1'
   98 |             scan1(v.sc[i][j])
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Execution timed out 2076 ms 364 KB Time limit exceeded
5 Halted 0 ms 0 KB -