Submission #136320

# Submission time Handle Problem Language Result Execution time Memory
136320 2019-07-25T06:58:54 Z 윤교준(#3260) Connect (CEOI06_connect) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
using namespace std;
typedef pair<int, int> pii;
const int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 };

int C[12][39][12][39];

bool B[12][39][4], isX[12][39];
char A[25][80];

int H, W, Ans;

int main() {
	scanf("%d%d ", &H, &W);
	for(int i = 0; i < H; i++) gets(A[i]);
	H >>= 1; W >>= 1;
	for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) {
		int y = i<<1|1, x = j<<1|1;
		if(' ' == A[y-1][x]) B[i][j][0] = true;
		if(' ' == A[y][x+1]) B[i][j][1] = true;
		if(' ' == A[y+1][x]) B[i][j][2] = true;
		if(' ' == A[y][x-1]) B[i][j][3] = true;
		isX[i][j] = 'X' == A[y][x];
	}
	for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) {
		fill(C[i][j][0], C[i][j][11]+39, INF);
		queue<int> PQ;
		C[i][j][i][j] = 0;
		PQ.push(i<<10|j);
		for(int key, y, x, dst; !PQ.empty();) {
			key = PQ.front(); PQ.pop();
			y = key >> 10; x = key & ((1<<10)-1);
			dst = C[i][j][y][x] + 1;
			for(int dr = 0, ny, nx; dr < 4; dr++) if(B[y][x][dr]) {
				ny = y+dy[dr]; nx = x+dx[dr];
				if(C[i][j][ny][nx] <= dst) continue;
				C[i][j][ny][nx] = dst;
				PQ.push(ny<<10|nx);
			}
		}
	}

	for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) {
		if(!isX[i][j]) continue;
		int mn = INF;
		for(int y = 0; y < H; y++) for(int x = 0; x < W; x++) {
			if(y == i && x == j) continue;
			if(!isX[y][x]) continue;
			upmin(mn, C[i][j][y][x]);
		}
		Ans += mn*2-1;
	}

	cout << (Ans >> 1) << endl;
	return 0;
}

Compilation message

connect.cpp: In function 'int main()':
connect.cpp:23:29: error: 'gets' was not declared in this scope
  for(int i = 0; i < H; i++) gets(A[i]);
                             ^~~~
connect.cpp:23:29: note: suggested alternative: 'fgets'
  for(int i = 0; i < H; i++) gets(A[i]);
                             ^~~~
                             fgets
connect.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d ", &H, &W);
  ~~~~~^~~~~~~~~~~~~~~~~