Submission #917315

# Submission time Handle Problem Language Result Execution time Memory
917315 2024-01-27T18:53:38 Z manizare Connect (CEOI06_connect) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define int long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
using namespace std ;   
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int 13 = 2e6 + 10 , inf= 1e18, mod = 998244353;
int n, m;
char a[2*13+1][2*90+10];
int how[13][90];
short memo[13][90][1<<13][2];
const short inf = 10000;
 
const char *b[3][11] = {
   { "+ +", "+ +", "+.+", "+ +", "+ +", "+ +", "+.+", "+.+", "+.+", "+ +", "+ +" },
   { "   ", ".X ", " X ", " X.", " X ", "...", " . ", ".. ", " ..", " ..", ".. " },
   { "+ +", "+ +", "+ +", "+ +", "+.+", "+ +", "+.+", "+ +", "+ +", "+.+", "+.+" },
};
 
short rec( int r, int c, int mask, int U, int reconstruct ) {
   if( r == n ) return rec( 0, c+1, mask, 0, reconstruct );
   if( c == m ) return 0;
 
   short &ret = memo[r][c][mask][U];
   if( !reconstruct && ret >= 0 ) return ret;
 
   ret = inf;
 
   int L = (mask>>r)&1;
   int R = a[2*r+1][2*c+2] == ' ';
   int D = a[2*r+2][2*c+1] == ' ';
   int X = a[2*r+1][2*c+1] == 'X';
 
   int h0=0, h1=0, h2=0, h3=0;
 
   #define tst(t0,t1,t2,t3) { \
      int v = t1 + rec( r+1, c, t2, t3, 0 ); \
      if( v < ret ) { ret = v; h0=t0; h1=t1; h2=t2; h3=t3; } \
   }
 
   if( !X && !L && !U && 1 && 1 ) tst(  0, 0, mask & ~(1<<r), 0 ); // empty
 
   if(  X &&  L && !U && 1 && 1 ) tst(  1, 1, mask & ~(1<<r), 0 ); // left
   if(  X && !L &&  U && 1 && 1 ) tst(  2, 1, mask & ~(1<<r), 0 ); // up
   if(  X && !L && !U && R && 1 ) tst(  3, 1, mask |  (1<<r), 0 ); // right
   if(  X && !L && !U && 1 && D ) tst(  4, 1, mask & ~(1<<r), 1 ); // down
 
   if( !X &&  L && !U && R && 1 ) tst(  5, 2, mask |  (1<<r), 0 ); // left-right
   if( !X && !L &&  U && 1 && D ) tst(  6, 2, mask & ~(1<<r), 1 ); // up-down
 
   if( !X &&  L &&  U && 1 && 1 ) tst(  7, 2, mask & ~(1<<r), 0 ); // left-up
   if( !X && !L &&  U && R && 1 ) tst(  8, 2, mask |  (1<<r), 0 ); // up-right
   if( !X && !L && !U && R && D ) tst(  9, 2, mask |  (1<<r), 1 ); // right-down
   if( !X &&  L && !U && 1 && D ) tst( 10, 2, mask & ~(1<<r), 1 ); // down-left
 
   if( reconstruct ) {
      how[r][c] = h0;
      rec( r+1, c, h2, h3, 1 );
   }
 
   return ret;
}
 
int main( void ) {
   scanf( "%d%d ", &n, &m );
   for( int r = 0; r < n; ++r ) {
     fgets( a[r], 90, stdin );
     int l = strlen(a[r]);
     while(a[r][l-1] == '\r' || a[r][l-1] == '\n') a[r][l-1] = 0;
   }
   n /= 2; m /= 2;
 
   memset( memo, -1, sizeof memo );
   printf( "%d\n", rec( 0, 0, 0, 0, 1 ) );
 
   for( int r = 0; r < n; ++r )
      for( int c = 0; c < m; ++c )
         for( int dr = 0; dr < 3; ++dr )
            for( int dc = 0; dc < 3; ++dc )
               if( b[dr][how[r][c]][dc] != ' ' )
                  a[2*r+dr][2*c+dc] = b[dr][how[r][c]][dc];
 
   for( int r = 0; r <= 2*n; ++r ) puts( a[r] );
   return 0;
}
/*

*/

Compilation message

connect.cpp:14:11: error: expected unqualified-id before numeric constant
   14 | const int 13 = 2e6 + 10 , inf= 1e18, mod = 998244353;
      |           ^~
cc1plus: error: '::main' must return 'int'
connect.cpp: In function 'int main()':
connect.cpp:72:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   72 |    scanf( "%d%d ", &n, &m );
      |            ~^      ~~
      |             |      |
      |             int*   long long int*
      |            %lld
connect.cpp:72:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   72 |    scanf( "%d%d ", &n, &m );
      |              ~^        ~~
      |               |        |
      |               int*     long long int*
      |              %lld
connect.cpp:72:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |    scanf( "%d%d ", &n, &m );
      |    ~~~~~^~~~~~~~~~~~~~~~~~~
connect.cpp:74:11: warning: ignoring return value of 'char* fgets(char*, int, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |      fgets( a[r], 90, stdin );
      |      ~~~~~^~~~~~~~~~~~~~~~~~~