結果
問題 | No.2946 Puyo |
ユーザー |
|
提出日時 | 2024-10-31 16:55:16 |
言語 | JavaScript (node v23.5.0) |
結果 |
AC
|
実行時間 | 1,418 ms / 2,000 ms |
コード長 | 1,547 bytes |
コンパイル時間 | 402 ms |
コンパイル使用メモリ | 7,204 KB |
実行使用メモリ | 159,744 KB |
最終ジャッジ日時 | 2024-10-31 16:55:58 |
合計ジャッジ時間 | 40,512 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
function Main(INPUT){ const input=INPUT.split("\n"); const [H,W]=input[0].split(" ").map(_=>parseInt(_)); const grid=input.filter((v,i)=>i>0); const res=[]; const check=Array(H).fill().map(_=>Array(W).fill().map(_=>false)); const del=Array(H).fill().map(_=>Array(W).fill().map(_=>false)); for(let i=0;i<H;i++){ for(let j=0;j<W;j++){ res.push([i,j]); } } while(res.length>0){ let cnt=0; let l=[]; let [x,y]=res.pop(); let q=[[x,y]]; if(grid[x][y]=="." || del[x][y] || check[x][y]) continue; check[x][y]=true; let c=grid[x][y]; while(q.length>0){ let [i,j]=q.pop(); cnt++; l.push([i,j]); if(i>0){ if(!check[i-1][j] && grid[i-1][j]==c){ check[i-1][j]=true; q.push([i-1,j]); } } if(i<H-1){ if(!check[i+1][j] && grid[i+1][j]==c){ check[i+1][j]=true; q.push([i+1,j]); } } if(j>0){ if(!check[i][j-1] && grid[i][j-1]==c){ check[i][j-1]=true; q.push([i,j-1]); } } if(j<W-1){ if(!check[i][j+1] && grid[i][j+1]==c){ check[i][j+1]=true; q.push([i,j+1]); } } } if(cnt>=4){ for(let[x,y] of l){ del[x][y]=true; } } } for(let i=0;i<H;i++){ a=""; for(let j=0;j<W;j++){ if(del[i][j]){ a+='.'; } else{ a+=grid[i][j]; } } console.log(a); } } Main(require("fs").readFileSync("/dev/stdin", "utf8"));