SHARE
TWEET

Untitled

a guest Aug 9th, 2017 154 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2.  
  3. #define forn( i,n ) for ( int i=0; i<(int)(n); i++ )
  4.  
  5. int n, m, a[100], val[5];
  6. int u1[1010], u2[1010], u3[1010], u4[1010];
  7. int wi[100], wj[100];
  8. bool u[7][7];
  9.  
  10. void solveTicket( int id ) {
  11.   forn( i, 76 ) wi[i] = wj[i] = -1;
  12.  
  13.   int x;
  14.   forn( i, 5 )
  15.     forn( j, 5 ) {
  16.       scanf( "%d", &x );
  17.       wi[x] = i;
  18.       wj[x] = j;
  19.       u[i][j] = false;
  20.     }
  21.  
  22.   u1[id] = u2[id] = u3[id] = u4[id] = 0;
  23.  
  24.   int cnt = 0;
  25.   forn( i, n ) {
  26.     if ( wi[ a[i] ] != -1 ) {
  27.       u[ wi[a[i]] ][ wj[a[i]] ] = 1;
  28.       cnt++;
  29.     }
  30.  
  31.     if ( i < 35 && !u1[id] ) {
  32.       if ( u[0][0] && u[0][4] && u[4][0] && u[4][4] ) {
  33.         u1[id] = i;
  34. //        res += val[0];
  35.       }
  36.     }
  37.  
  38.     if ( i < 40 && !u2[id] ) {
  39.       if ( u[2][0] && u[2][1] && u[2][2] && u[2][3] && u[2][4] ) {
  40.         u2[id] = i;
  41. //        res += val[1];
  42.       }
  43.     }
  44.  
  45.     if ( i < 45 && !u3[id] ) {
  46.       if ( u[0][0] && u[1][1] && u[2][2] && u[3][3] && u[4][4] &&
  47.            u[0][4] && u[1][3] && u[3][1] && u[4][0] ) {
  48.         u3[id] = i;
  49. //        res += val[2];
  50.       }
  51.     }
  52.  
  53.     if ( !u4[id] ) {
  54.       if ( cnt == 25 ) {
  55.         u4[id] = i;
  56.       }
  57.     }  
  58.   }
  59. }
  60.  
  61. int main() {
  62.   int tc;
  63.   scanf( "%d", &tc );
  64.   for ( int q=1; q<=tc; q++ ) {
  65.     scanf( "%d %d", &n, &m );
  66.     forn( i, n ) scanf( "%d", &a[i] );
  67.     forn( i, 4 ) scanf( "%d", &val[i] );
  68.     if ( q > 1 ) printf( "\n" );
  69.     printf( "Case %d:\n", q );
  70.     int min4 = 100;
  71.     forn( i, m ) {
  72.       solveTicket( i );
  73.       if ( u4[i] != 0 && u4[i] < min4 )
  74.         min4 = u4[i];
  75.     }
  76.  
  77.     forn( i, m ) {
  78.       int res = 0;
  79.       if ( u1[i] != 0 && u1[i] <= min4 ) res += val[0];
  80.       if ( u2[i] != 0 && u2[i] <= min4 ) res += val[1];
  81.       if ( u3[i] != 0 && u3[i] <= min4 ) res += val[2];
  82.       if ( u4[i] != 0 && u4[i] <= min4 ) res += val[3];
  83. //      printf( "%d %d %d %d\n", u1[i], u2[i], u3[i], u4[i] );
  84.       printf( "%d\n", res );
  85.     }
  86.   }
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top