# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
339350 | beksultan04 | Riddick's Cube (IZhO13_riddicks) | C++14 | 564 ms | 65540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 <bool, vector <vector <int> > > ,int> mp;
deque <pair <bool, vector <vector <int> > > >q;
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;
}
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;
}
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];
}
}
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];
}
}
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];
}
}
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];
}
}
// pair <bool,vector <vector <int > >> t;
// t.sc = v;
// for (i=0;i<n;++i){
// for (j=0;j<m;++j)
// cout <<t.sc[i][j]<<" ";
// endi
// }
// fun4(t,0);
// for (i=0;i<n;++i){
// for (j=0;j<m;++j)
// cout <<t.sc[i][j]<<" ";
// endi
// }
// fun3(t,0);
// for (i=0;i<n;++i){
// for (j=0;j<m;++j)
// cout <<t.sc[i][j]<<" ";
// endi
// }
mp[{0,v}]=1;
q.pb({0,v});
int h=0;
while (!q.empty()){
pair <bool,vector <vector <int> >> t = q[0];
q.pop_front();
if (mp[t] == 100500)break;
if (is_row(t.sc) || is_columm(t.sc)){
cout <<mp[t]-1;
ret 0;
}
if (t.fr == 0){
for (i=0;i<m;++i){
{
int c = mp[t];
fun3(t,i);
if (!mp[t]){
mp[t] = c+1;
q.pb(t);
}
}
{
int c = mp[t];
fun4(t,i);
if (!mp[t]){
mp[t] = c+1;
q.pb(t);
}
}
}
}
for (i=0;i<t.sc.size();++i){
{
pair <bool,vector <vector <int> >> to = t;
fun1(to.sc[i]);
to.fr = 1;
if (!mp[to] && !mp[{0,to.sc}]){
mp[to] = mp[t]+1;
q.pb(to);
}
}
{
pair <bool,vector <vector <int> >> to = t;
fun2(to.sc[i]);
to.fr = 1;
if ( !mp[to] && !mp[{0,to.sc}]){
mp[to] = mp[t]+1;
q.pb(to);
}
}
}
}
cout <<100500;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |