提出 #22290363


ソースコード 拡げる

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int H, W;
string S[4];
int cnt = 0;
//---------------------------------------------------------------------------------------------------
int visited[4][4];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
string dfs(int x, int y, int done = 1) {
	if (done == cnt) {
		return to_string(y + 1) + " " + to_string(x + 1) + "\n";
	}

	visited[y][x] = 1;

	rep(d, 0, 4) {
		int xx = x + dx[d];
		int yy = y + dy[d];

		if (0 <= xx && xx < W && 0 <= yy && yy < H) {
			if (!visited[yy][xx] && S[yy][xx] == '#') {
				auto res = dfs(xx, yy, done + 1);
				if (res != "") {
					return res + to_string(y + 1) + " " + to_string(x + 1) + "\n";
				}
			}
		}
	}

	visited[y][x] = 0;

	return "";
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W;
	rep(y, 0, H) cin >> S[y];

	rep(y, 0, H) rep(x, 0, W) if (S[y][x] == '#') cnt++;
	printf("%d\n", cnt);

	rep(y, 0, H) rep(x, 0, W) if (S[y][x] == '#') {
		string res = dfs(x, y);
		if (res != "") {
			printf("%s", res.c_str());
			return;
		}
	}
}





提出情報

提出日時
問題 G - ヘビ
ユーザ hamayanhamayan
言語 C++ (GCC 9.2.1)
得点 6
コード長 2410 Byte
結果 AC
実行時間 7 ms
メモリ 3708 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 6 / 6
結果
AC × 3
AC × 58
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All handmade_00.txt, handmade_01.txt, handmade_02.txt, handmade_03.txt, handmade_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, random_45.txt, random_46.txt, random_47.txt, random_48.txt, random_49.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
handmade_00.txt AC 7 ms 3660 KiB
handmade_01.txt AC 2 ms 3652 KiB
handmade_02.txt AC 2 ms 3600 KiB
handmade_03.txt AC 5 ms 3608 KiB
handmade_04.txt AC 2 ms 3652 KiB
random_00.txt AC 2 ms 3628 KiB
random_01.txt AC 2 ms 3608 KiB
random_02.txt AC 2 ms 3632 KiB
random_03.txt AC 2 ms 3708 KiB
random_04.txt AC 3 ms 3688 KiB
random_05.txt AC 2 ms 3620 KiB
random_06.txt AC 2 ms 3688 KiB
random_07.txt AC 2 ms 3624 KiB
random_08.txt AC 2 ms 3600 KiB
random_09.txt AC 2 ms 3536 KiB
random_10.txt AC 2 ms 3680 KiB
random_11.txt AC 2 ms 3668 KiB
random_12.txt AC 2 ms 3604 KiB
random_13.txt AC 2 ms 3692 KiB
random_14.txt AC 2 ms 3672 KiB
random_15.txt AC 3 ms 3708 KiB
random_16.txt AC 2 ms 3604 KiB
random_17.txt AC 2 ms 3700 KiB
random_18.txt AC 2 ms 3548 KiB
random_19.txt AC 2 ms 3680 KiB
random_20.txt AC 2 ms 3616 KiB
random_21.txt AC 3 ms 3644 KiB
random_22.txt AC 3 ms 3540 KiB
random_23.txt AC 3 ms 3700 KiB
random_24.txt AC 2 ms 3540 KiB
random_25.txt AC 2 ms 3548 KiB
random_26.txt AC 3 ms 3596 KiB
random_27.txt AC 2 ms 3700 KiB
random_28.txt AC 5 ms 3664 KiB
random_29.txt AC 2 ms 3700 KiB
random_30.txt AC 2 ms 3648 KiB
random_31.txt AC 2 ms 3600 KiB
random_32.txt AC 2 ms 3624 KiB
random_33.txt AC 2 ms 3616 KiB
random_34.txt AC 1 ms 3680 KiB
random_35.txt AC 2 ms 3636 KiB
random_36.txt AC 2 ms 3560 KiB
random_37.txt AC 2 ms 3564 KiB
random_38.txt AC 2 ms 3600 KiB
random_39.txt AC 2 ms 3648 KiB
random_40.txt AC 3 ms 3536 KiB
random_41.txt AC 3 ms 3628 KiB
random_42.txt AC 2 ms 3536 KiB
random_43.txt AC 2 ms 3664 KiB
random_44.txt AC 2 ms 3600 KiB
random_45.txt AC 2 ms 3596 KiB
random_46.txt AC 2 ms 3664 KiB
random_47.txt AC 2 ms 3704 KiB
random_48.txt AC 2 ms 3620 KiB
random_49.txt AC 2 ms 3628 KiB
sample_01.txt AC 3 ms 3596 KiB
sample_02.txt AC 2 ms 3700 KiB
sample_03.txt AC 2 ms 3696 KiB