結果
問題 | No.697 池の数はいくつか |
ユーザー | lunnear |
提出日時 | 2019-01-12 06:12:28 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 463 ms / 6,000 ms |
コード長 | 2,934 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 36,096 KB |
実行使用メモリ | 20,512 KB |
最終ジャッジ日時 | 2024-04-25 20:21:23 |
合計ジャッジ時間 | 4,467 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,944 KB |
testcase_19 | AC | 1 ms
6,944 KB |
testcase_20 | AC | 1 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 1 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 54 ms
6,940 KB |
testcase_25 | AC | 52 ms
6,944 KB |
testcase_26 | AC | 51 ms
6,944 KB |
testcase_27 | AC | 52 ms
6,944 KB |
testcase_28 | AC | 51 ms
6,944 KB |
testcase_29 | AC | 75 ms
20,112 KB |
testcase_30 | AC | 457 ms
20,388 KB |
testcase_31 | AC | 78 ms
20,324 KB |
testcase_32 | AC | 463 ms
20,488 KB |
testcase_33 | AC | 450 ms
20,488 KB |
testcase_34 | AC | 457 ms
20,512 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:71:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 71 | scanf("%d %d", &h, &w); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <list> struct Vector2 { short x, y; }; struct Square { char val = -1; bool check = false; }; class Field { public: Field(int w, int h); ~Field(); private: int w, h; Square *sq; public: Square* Get(int x, int y); bool isField(int x, int y); }; Field::Field(int w, int h) { this->w = w; this->h = h; sq = new Square[w * h]; } Field::~Field() { delete[] sq; } Square* Field::Get(int x, int y) { return &sq[x + y * w]; } bool Field::isField(int x, int y) { if(x < 0) return false; if(y < 0) return false; if(x >= w) return false; if(y >= h) return false; return true; } int main(void) { int w, h; scanf("%d %d", &h, &w); getchar(); Field f(w, h); int zeros = 0; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ Square *s = f.Get(x, y); s->val = getchar() - '0'; if(s->val == 0) zeros++; getchar(); } } int *min = (w < h)? &w:&h; if(*min > zeros) { printf("1\n"); return 0; } int count = 0; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ Square *s = f.Get(x, y); if(s->check) continue; if(s->val != 1) continue; std::list<Vector2> history; while(1) { s->check = true; bool next = false; const Vector2 d[4] = { {-1, 0}, { 1, 0}, { 0, -1}, { 0, 1} }; for(int i = 0; i < 4; i++) { if(!f.isField(x + d[i].x, y + d[i].y)) continue; Square *to = f.Get(x + d[i].x, y + d[i].y); if(to->val && !to->check) { Vector2 v; v.x = x; v.y = y; history.push_back(v); s = to; x += d[i].x; y += d[i].y; next = true; break; } } if(next) continue; if(history.empty()) break; Vector2 v = history.back(); s = f.Get(v.x, v.y); x = v.x; y = v.y; history.pop_back(); } count++; } } printf("%d\n", count); return 0; }