ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1015. Test the Difference!

I passed the test with all 720 permutations correct, but it's still WA. What may be wrong with this code?
Posted by Osama Ben Laden 12 Feb 2002 00:19
#include <fstream.h>

unsigned long n;
int a[6];
// 0 LEFT   on the left side of the die,
// 1 RIGHT  then on the right side,
// 2 TOP    on the top,
// 3 FRONT  on the forward side,
// 4 BOTTOM on the bottom
// 5 BACK   and on the backward side

void permut(int x0, int x1, int x2, int x3, int x4, int x5)
{
 int b[6];
 b[0] = a[x0]; b[1] = a[x1]; b[2] = a[x2];
 b[3] = a[x3]; b[4] = a[x4]; b[5] = a[x5];
 for(int i=0; i<6; i++) a[i] = b[i];
}
long dig[200];
long sh[200];
int *w;
long *s;
int main()
{
 cin>>n;
 w = new int[n];
 s = new long[n];
 int v[6]; int sm=1, j; long i;
 for(j=1; j<6; sm*=j++) v[6-j] = sm;
 for(j=0; j<200; j++) dig[j] = 0;
 for(i=0; i<n; i++)
 {
  for(int j=0; j<6; j++) {cin>>a[j]; a[j]--;}
  if(!a[3] | !a[5]) permut(3,5,2,1,4,0);
  while(a[0]) permut(4,2,0,3,1,5);
  while(a[2] != (a[1]==1 ? 2:1) ) permut(0,1,3,4,5,2);
  int x = 0;
  for(int k=1; k<6; k++)
  {
    x += v[k]*(a[k]-1);
    for(int t=k+1; t<6; t++) if(a[t]>a[k]) a[t]--;
  }
  w[i] = x;  dig[x]++;
 }

 long q = 0;
 for(j=1; j<200; j++)
  {sh[j] = sh[j-1]+dig[j-1]; if(dig[j-1]) q++;}
 cout<<q;
 for(i=0; i<n; i++) s[sh[w[i]]++] = i;
 long k = 0;
 for(j=0; j<200; j++) if(dig[j])
 {
  cout<<'\n';
  for(i=0; i<dig[j]; i++) cout<<(1+s[k++])<<' ';
 }
 cout<<'\n';
 delete w;
 delete s;
 return 0;
}