結果

問題 No.2946 Puyo
コンテスト
ユーザー tnakao0123
提出日時 2024-11-02 12:45:46
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,302 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 308 ms
コンパイル使用メモリ 76,940 KB
実行使用メモリ 12,720 KB
最終ジャッジ日時 2026-07-06 03:10:07
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/deque:64,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/queue:68,
                 from main.cpp:7:
In function 'void std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int*; _Tp = int]',
    inlined from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:979:21,
    inlined from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:1011:20,
    inlined from 'int main()' at main.cpp:38:7:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:925:18: warning: 'void* __builtin_memset(void*, int, long unsigned int)' specified bound between 18446744065119617024 and 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
  925 |         *__first = __val;
      |         ~~~~~~~~~^~~~~~~

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2946.cc:  No.2946 Puyo - yukicoder
 */

#include<cstdio>
#include<queue>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_H = 1000;
const int MAX_W = 1000;
const int MAX_N = MAX_H * MAX_W;
const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };

/* typedef */

using qi = queue<int>;

/* global variables */

char fs[MAX_N + 4];
int gs[MAX_N], ss[MAX_N];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  int n = h * w;
  for (int i = 0; i < n; i++) scanf("%s", fs + i * w);

  fill(gs, gs + n, -1);
  int gn = 0;
  
  for (int st = 0; st < n; st++)
    if (gs[st] < 0 && fs[st] != '.') {
      int id = gs[st] = gn++;
      ss[id] = 1;
      qi q;
      q.push(st);

      while (! q.empty()) {
	int u = q.front(); q.pop();
	int uy = u / w, ux = u % w;
	for (int di = 0; di < 4; di++) {
	  int vy = uy + dys[di], vx = ux + dxs[di], v = vy * w + vx;
	  if (vy >= 0 && vy < h && vx >= 0 && vx < w &&
	      gs[v] < 0 && fs[v] == fs[st]) {
	    gs[v] = id, ss[id]++;
	    q.push(v);
	  }
	}
      }
    }

  for (int y = 0, u = 0; y < h; y++) {
    for (int x = 0; x < w; x++, u++) {
      if (gs[u] >= 0 && ss[gs[u]] >= 4) putchar('.');
      else putchar(fs[u]);
    }
    putchar('\n');
  }
  
  return 0;
}
0