Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: theem1502

Problemset: เกาะที่ใหญ่ที่สุด

Language: cpp

Time: 0.004 second

Submitted On: 2026-02-21 20:30:04

#include <bits/stdc++.h>
using namespace std;
    int row, collumn;

    int dix[4] = {0,0,-1,1};
    int diy[4] = {1,-1,0,0};

    int dfs(int currentx, int currenty, vector<string> &thearray) {
            if (currentx < 0 || currenty < 0 || currentx >= row || currenty >= collumn) {
                return 0;
            }
            if (thearray[currentx][currenty] == '0') {
                return 0;
            }
            thearray[currentx][currenty] = '0';
            int sum = 1;
            for (int i = 0; i < 4; i++) {
                sum += dfs(currentx + dix[i], currenty + diy[i], thearray);
            }
            return sum;

    }

int main() {

    cin >> row >> collumn;
    vector<string> thearray(row);
    for (int i = 0; i < row; i++) {
        cin >> thearray[i];
    }
    int maxvalue = 0;
    for (int i = 0; i< row; i++) {
        for (int j = 0; j < collumn; j++) {
            if (thearray[i][j] == '1') {
                maxvalue = max(maxvalue, dfs(i, j, thearray));
            }
        }
    }
    cout << maxvalue;

}