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!

Why do I get WA??? What's wrong with my program?
Posted by Grebnov Ilya[ISPU] 20 Mar 2003 22:56
CONST
  MaxN = 1000;

TYPE
  TDice = ARRAY[1..6] OF Byte;

VAR
  N, I, J, M : LongInt;
  Kind : ARRAY[1..MaxN] OF Integer;
  Kinds : LongInt;
  C : TDice;
  Dices : ARRAY[1..MaxN] OF TDice;

  PROCEDURE RotateLeft(VAR T : TDice);
  VAR
    Temp : Byte;
  BEGIN
    Temp := T[4];
    T[4] := T[2];
    T[2] := T[6];
    T[6] := T[1];
    T[1] := Temp;
  END;

  PROCEDURE RotateUp(VAR T : TDice);
  VAR
    Temp : Byte;
  BEGIN
    Temp := T[4];
    T[4] := T[5];
    T[5] := T[6];
    T[6] := T[3];
    T[3] := Temp;
  END;

  PROCEDURE RotateBack(VAR T : TDice);
  VAR
    Temp : Byte;
  BEGIN
    Temp := T[5];
    T[5] := T[1];
    T[1] := T[3];
    T[3] := T[2];
    T[2] := Temp;
  END;

  PROCEDURE Change(VAR T : TDice; A, B, C : Integer);
  VAR
    I : LongInt;
  BEGIN
    FOR I := 1 TO A DO RotateLeft(T);
    FOR I := 1 TO B DO RotateUp(T);
    FOR I := 1 TO C DO RotateBack(T);
  END;

  FUNCTION Find(T : TDice; Index : LongInt) : LongInt;
  VAR
    I, J : LongInt;
    Ok : Boolean;
  BEGIN
    FOR I := 1 TO Index-1 DO
      BEGIN
        Ok := True;
        FOR J := 1 TO 6 DO
          IF T[J] <> Dices[I][J] THEN Ok := False;
        IF (Ok) THEN
          BEGIN
            Find := Kind[I];
            Exit;
          END;
      END;
    Find := 0;
  END;

  PROCEDURE Solve(T : TDice; Index : LongInt);
  VAR
    I, J, K, Lab : LongInt;
    Tmp : TDice;
  BEGIN
    FOR J := 0 TO 3 DO
      FOR I := 0 TO 3 DO
        FOR K := 0 TO 3 DO
          BEGIN
            Tmp := T;
            Change(Tmp, I, J, K);
            Lab := Find(Tmp, Index);
            IF Lab <> 0 THEN
              BEGIN
                Kind[Index] := Lab;
                Exit;
              END;
          END;
    Inc(Kinds);
    Kind[Index] := Kinds;
  END;
BEGIN
  Kinds := 0;
  ReadLn(N);
  FOR I := 1 TO N DO
    BEGIN
      FOR J := 1 TO 6 DO Read(C[J]);
      ReadLn;
      Dices[I] := C;
      Solve(C, I);
    END;
  WriteLn(Kinds);
  FOR I := 1 TO Kinds DO
    BEGIN
      J := 1;
      WHILE Kind[J] <> I DO Inc(J);
      Write(J);
      FOR M := J+1 TO N DO
        IF Kind[M] = I THEN Write(' ', M);
      IF I <> Kinds THEN WriteLn;
    END;
END.