Go to diff to previous submission
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cctype> #include<climits> #include<algorithm> #include<utility> #include<string> #include<deque> #include<list> #include<map> #include<queue> #include<set> #include<stack> #include<vector> using namespace std; #define REP(i,N) for (int i = 0; i < (N); i++) #define FOR(i,a,b) for (int i = (a); i <= (b); i++) #define FORI(i,a,b) for (int i = (a); i < (b); i++) #define FORD(i,a,b) for (int i = (a)-1; i >= (b); i--) #define DP(arg...) fprintf(stderr, ## arg) typedef long long ll; typedef long double ld; typedef pair<int,int> ii; char P[15][5][6] = { { {".XX.."}, {"XX..."}, {".X..."}, {"....."}, {"....."} }, { {"X...."}, {"X...."}, {"X...."}, {"X...."}, {"X...."} }, { {"X...."}, {"X...."}, {"X...."}, {"XX..."}, {"....."} }, { {".X..."}, {".X..."}, {"XX..."}, {"X...."}, {"....."} }, { {"XX..."}, {"XX..."}, {"X...."}, {"....."}, {"....."} }, { {"XXX.."}, {".X..."}, {".X..."}, {"....."}, {"....."} }, { {"X.X.."}, {"XXX.."}, {"....."}, {"....."}, {"....."} }, { {"X...."}, {"X...."}, {"XXX.."}, {"....."}, {"....."} }, { {"X...."}, {"XX..."}, {".XX.."}, {"....."}, {"....."} }, { {".X..."}, {"XXX.."}, {".X..."}, {"....."}, {"....."} }, { {".X..."}, {"XX..."}, {".X..."}, {".X..."}, {"....."} }, { {"XX..."}, {".X..."}, {".XX.."}, {"....."}, {"....."} } }; char A[4]; int a[4]; char poz[12][8][5][6]; int op[4][2] = {{1,1}, {1, -1}, {-1, 1}, {-1, -1}}; int res1[25][25]; int res2[25][25]; int table(char c) { switch(c) { case 'F': return 0; case 'I': return 1; case 'L': return 2; case 'N': return 3; case 'P': return 4; case 'T': return 5; case 'U': return 6; case 'V': return 7; case 'W': return 8; case 'X': return 9; case 'Y': return 10; case 'Z': return 11; } } struct Bod{ int x, y; bool operator<(const Bod &p) const { return (x<p.x || (x==p.x && y<p.y)); } bool operator==(const Bod &p) const { return (x==p.x && y==p.y); } }; struct Konfig{ Bod body[10]; bool operator<(const Konfig &p) const { for(int i=0;i<10;++i){ if(body[i]<p.body[i]) return true; if(p.body[i]<body[i]) return false; } return false; } bool operator==(const Konfig &p) const { for(int i=0;i<10;++i){ if(!(body[i]==p.body[i])) return false; } return true; } void sortp(){ sort(body, body+10); } }; vector<Konfig> dobre[12][12]; //vector<Pozice> ppp[12][8]; void generate(int p1, int p2){ //bool exist = 0; vector<Konfig> nonuni; REP(i, 8) REP(j, 8) REP(x1, 6) REP(y1, 6) { REP(p, 20) REP(q, 20) res1[p][q] = 0; REP(p, 5) REP(q, 5) { char c = poz[p1][i][p][q]; res1[p][q] += (c=='X')?1:0; c = poz[p2][j][p][q]; res1[p+x1][q+y1] += (c=='X')?1:0; } bool kolize = 0; REP(p, 10) REP(q, 10) if (res1[p][q]>1) kolize = 1; if (kolize) continue; int pp1, qq1; REP(p, 10) REP(q, 10) { if (res1[p][q]==1) { pp1 = p; qq1 = q; goto pryc1; } } pryc1: Konfig k; int bi = 0; REP(p, 10) REP(q, 10){ if(res1[p][q]){ k.body[bi].x = p-pp1; k.body[bi].y = q-qq1; ++bi; } } nonuni.push_back(k); } REP(i, nonuni.size()) nonuni[i].sortp(); sort(nonuni.begin(),nonuni.end()); int ui = 0; REP(i, nonuni.size()){ if(i == 0 || !(nonuni[i]==nonuni[i-1])){ dobre[p1][p2].push_back(nonuni[i]); } } // printf("%d\n",dobre[p1][p2].size()); } void solve() { REP(i, 4) a[i] = table(A[i]); if(a[0]>a[1]) swap(a[0], a[1]); if(a[2]>a[3]) swap(a[2], a[3]); //int poz2 = 0; bool ok = 0; REP(i, dobre[a[0]][a[1]].size()) REP(j, dobre[a[2]][a[3]].size()) if( dobre[a[0]][a[1]][i]== dobre[a[2]][a[3]][j]){ ok = 1; goto ven; } //for(int poz1=0;poz1<dobre[a[0]][a[1]].size();++poz1); ven: printf("%s\n", ok?"YES":"NO"); } int main() { REP(i, 12) { //REP(k, 4) { REP(x, 5) REP(y, 5) { poz[i][0][x][y] = P[i][x][y]; poz[i][1][x][y] = P[i][4-x][y]; poz[i][2][x][y] = P[i][x][4-y]; poz[i][3][x][y] = P[i][4-x][4-y]; poz[i][4][x][y] = P[i][y][x]; poz[i][5][x][y] = P[i][4-y][4-x]; poz[i][6][x][y] = P[i][y][4-x]; poz[i][7][x][y] = P[i][4-y][x]; } //} } REP(i, 12) FOR(j, i, 11) generate(i, j); while (scanf(" %c %c %c %c", &A[0], &A[1], &A[2], &A[3]) != EOF) { solve(); } /*REP(i, 12) FOR(j, i, 11) REP(k, 12) FOR (l, k, 11) { a[0] = i; a[1] = j; a[2] = k; a[3] = l; solve(); }*/ return 0; } /* REP(i, 12) REP(j, 8) sort(ppp[i][j].begin(), ppp[i][j].end()); REP(i, 12) REP(j, 8) REP(k, 5) REP(l, 5) { if (poz[i][j][k][l]=='X') ppp[i][j].push_back((Pozice){k,l}); } bool sloz(int a, i, int b, int j, vector<Pozice> &poz) { vector<Pozice> ans; REP(q, ppp[a][i].size()) ans.push_back(ppp[a][i][q]); REP(q, ppp[b][j].size()) ans.push_back(ppp[b][j][q]); sort(ans.begin(), ans.end()); REP(i, ans.size()-1) if (ans[i]==ans[i+1]) return false; return true; } REP(k, 8) REP(l, 8) REP(x2, 5) REP(y2, 5) { REP(p, 10) REP(q, 10) res2[p][q] = 0; REP(p, 5) REP(q, 5) { char c = poz[a[2]][k][p][q]; res2[p][q] += (c=='X')?1:0; c = poz[a[3]][l][p][q]; res2[p+x2][q+y2] += (c=='X')?1:0; } bool kolize = 0; REP(p, 10) REP(q, 10) if (res2[p][q]>1) kolize = 1; if (kolize) continue; bool stejne = 1; int pp1, qq1, pp2, qq2; REP(p, 10) REP(q, 10) { if (res1[p][q]==1) { pp1 = p; qq1 = q; goto pryc1; } } pryc1: REP(p, 10) REP(q, 10) { if (res2[p][q]==1) { pp2 = p; qq2 = q; goto pryc2; } } pryc2: REP(p, 10) REP(q, 10) if (res1[p+pp1][q+qq1]!=res2[p+pp2][q+qq2]) stejne = false; if (stejne) { exist = true; goto ven; } } */
--- c5.s862.cteam022.fp.cpp.0.fp.cpp +++ c5.s975.cteam022.fp.cpp.0.fp.cpp @@ -141,13 +141,53 @@ } -void solve() { - REP(i, 4) a[i] = table(A[i]); - bool exist = 0; - REP(i, 8) REP(j, 8) REP(x1, 5) REP(y1, 5) { - REP(p, 10) REP(q, 10) res1[p][q] = 0; +struct Bod{ + int x, y; + bool operator<(const Bod &p) const { + return (x<p.x || (x==p.x && y<p.y)); + } + bool operator==(const Bod &p) const { + return (x==p.x && y==p.y); + } +}; +struct Konfig{ + Bod body[10]; + bool operator<(const Konfig &p) const { + for(int i=0;i<10;++i){ + if(body[i]<p.body[i]) + return true; + + if(p.body[i]<body[i]) + return false; + } + + return false; + } + bool operator==(const Konfig &p) const { + for(int i=0;i<10;++i){ + if(!(body[i]==p.body[i])) + return false; + } + return true; + } + void sortp(){ + sort(body, body+10); + } +}; + +vector<Konfig> dobre[12][12]; + + +//vector<Pozice> ppp[12][8]; + +void generate(int p1, int p2){ + //bool exist = 0; + vector<Konfig> nonuni; + + REP(i, 8) REP(j, 8) REP(x1, 6) REP(y1, 6) { + REP(p, 20) REP(q, 20) res1[p][q] = 0; REP(p, 5) REP(q, 5) { - char c = poz[a[0]][i][p][q]; + char c = poz[p1][i][p][q]; res1[p][q] += (c=='X')?1:0; - c = poz[a[1]][j][p][q]; + c = poz[p2][j][p][q]; res1[p+x1][q+y1] += (c=='X')?1:0; } @@ -155,5 +195,115 @@ REP(p, 10) REP(q, 10) if (res1[p][q]>1) kolize = 1; if (kolize) continue; - REP(k, 8) REP(l, 8) REP(x2, 5) REP(y2, 5) { + + int pp1, qq1; + REP(p, 10) REP(q, 10) { + if (res1[p][q]==1) { + pp1 = p; qq1 = q; goto pryc1; + } + } + pryc1: + + Konfig k; + int bi = 0; + REP(p, 10) REP(q, 10){ + if(res1[p][q]){ + k.body[bi].x = p-pp1; + k.body[bi].y = q-qq1; + ++bi; + } + } + + nonuni.push_back(k); + + } + + REP(i, nonuni.size()) + nonuni[i].sortp(); + + sort(nonuni.begin(),nonuni.end()); + + int ui = 0; + REP(i, nonuni.size()){ + if(i == 0 || !(nonuni[i]==nonuni[i-1])){ + dobre[p1][p2].push_back(nonuni[i]); + } + } + +// printf("%d\n",dobre[p1][p2].size()); +} + + +void solve() { + REP(i, 4) a[i] = table(A[i]); + + if(a[0]>a[1]) + swap(a[0], a[1]); + if(a[2]>a[3]) + swap(a[2], a[3]); + + //int poz2 = 0; + bool ok = 0; + REP(i, dobre[a[0]][a[1]].size()) + REP(j, dobre[a[2]][a[3]].size()) + if( dobre[a[0]][a[1]][i]== dobre[a[2]][a[3]][j]){ + ok = 1; + goto ven; + } + + //for(int poz1=0;poz1<dobre[a[0]][a[1]].size();++poz1); + +ven: + printf("%s\n", ok?"YES":"NO"); +} + +int main() { + REP(i, 12) { + //REP(k, 4) { + REP(x, 5) REP(y, 5) { + poz[i][0][x][y] = P[i][x][y]; + poz[i][1][x][y] = P[i][4-x][y]; + poz[i][2][x][y] = P[i][x][4-y]; + poz[i][3][x][y] = P[i][4-x][4-y]; + poz[i][4][x][y] = P[i][y][x]; + poz[i][5][x][y] = P[i][4-y][4-x]; + poz[i][6][x][y] = P[i][y][4-x]; + poz[i][7][x][y] = P[i][4-y][x]; + } + //} + } + + REP(i, 12) FOR(j, i, 11) + generate(i, j); + while (scanf(" %c %c %c %c", &A[0], &A[1], &A[2], &A[3]) != EOF) { + solve(); + } + /*REP(i, 12) FOR(j, i, 11) REP(k, 12) FOR (l, k, 11) { + a[0] = i; a[1] = j; a[2] = k; a[3] = l; + solve(); + }*/ + return 0; +} + +/* + + REP(i, 12) REP(j, 8) sort(ppp[i][j].begin(), ppp[i][j].end()); + + REP(i, 12) REP(j, 8) REP(k, 5) REP(l, 5) { + if (poz[i][j][k][l]=='X') + ppp[i][j].push_back((Pozice){k,l}); + } + +bool sloz(int a, i, int b, int j, vector<Pozice> &poz) { + vector<Pozice> ans; + REP(q, ppp[a][i].size()) ans.push_back(ppp[a][i][q]); + REP(q, ppp[b][j].size()) ans.push_back(ppp[b][j][q]); + sort(ans.begin(), ans.end()); + REP(i, ans.size()-1) if (ans[i]==ans[i+1]) return false; + return true; +} + + + +REP(k, 8) REP(l, 8) REP(x2, 5) REP(y2, 5) { REP(p, 10) REP(q, 10) res2[p][q] = 0; REP(p, 5) REP(q, 5) { @@ -188,28 +338,3 @@ } } - } -ven: - if (exist) printf("YES\n"); - else printf("NO\n"); -} - -int main() { - REP(i, 12) { - //REP(k, 4) { - REP(x, 5) REP(y, 5) { - poz[i][0][x][y] = P[i][x][y]; - poz[i][1][x][y] = P[i][4-x][y]; - poz[i][2][x][y] = P[i][x][4-y]; - poz[i][3][x][y] = P[i][4-x][4-y]; - poz[i][4][x][y] = P[i][y][x]; - poz[i][5][x][y] = P[i][4-y][4-x]; - poz[i][6][x][y] = P[i][y][4-x]; - poz[i][7][x][y] = P[i][4-y][x]; - } - //} - } - while (scanf(" %c %c %c %c", &A[0], &A[1], &A[2], &A[3]) != EOF) { - solve(); - } - return 0; -} +*/