結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-26 09:40:21 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,333 bytes |
| コンパイル時間 | 345 ms |
| コンパイル使用メモリ | 30,976 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 15:10:18 |
| 合計ジャッジ時間 | 932 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.c: In function 'in':
main.c:6:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
6 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:9:24: note: in expansion of macro 'gc'
9 | int n = 0, c = gc();
| ^~
main.c: In function 'outs':
main.c:7:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
7 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:14:33: note: in expansion of macro 'pc'
14 | void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
| ^~
ソースコード
// yukicoder: No.13 囲みたい!
// 2019.5.26 bal4u
#include <stdio.h>
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
return n;
}
void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
typedef struct { int r, c, pr, pc; } Q;
Q q[10005]; int top;
char vis[103][103];
int W, H;
int map[103][103];
int mv[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}};
int dfs(int rr, int cc, int val) {
int i, r, c, pr, pc;
q[0].r = rr, q[0].c = cc, pr = -1, top = 1;
while (top) {
r = q[--top].r, c = q[top].c, pr = q[top].pr, pc = q[top].pc;
if (vis[r][c]) return 1;
vis[r][c] = 1;
for (i = 0; i < 4; i++) {
rr = r + mv[i][0], cc = c + mv[i][1];
if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
if (rr == pr && cc == pc) continue;
if (map[rr][cc] == val) {
q[top].r = rr, q[top].c = cc, q[top].pr = r, q[top++].pc = c;
}
}
}
return 0;
}
int main()
{
int r, c;
W = in(), H = in();
if (W == 1 || H == 1) { outs("impossible"); return 0; }
for (r = 0; r < H; r++) for (c = 0; c < W; c++) map[r][c] = in();
for (r = 0; r < H; r++) for (c = 0; c < W; c++) if (!vis[r][c]) {
if (dfs(r, c, map[r][c])) { outs("possible"); return 0; }
}
outs("impossible");
return 0;
}
bal4u