intmain(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, m, k; cin >> n >> m >> k; vector<string> data(n); vector<vector<bool>> vis(n); for (int i = 0; i < n; ++i) { cin >> data[i]; vis[i].resize(m, false); } bool flag = true;
auto findCell = [&](int x, int y) { int cur = -1; for (int i = 0; i < n; ++i) { bool left = x >= i && y >= i && data[y - i][x - i] == '*'; bool right = x + i < m && y >= i && data[y - i][x + i] == '*'; if (left && right) { cur++; vis[y - i][x - i] = true; vis[y - i][x + i] = true; } elsebreak; } if (cur < k) flag = false; };
auto tryCell = [&](int x, int y) { int cur = -1; for (int i = 0; i < n; ++i) { bool left = x >= i && y >= i && data[y - i][x - i] == '*'; bool right = x + i < m && y >= i && data[y - i][x + i] == '*'; if (left && right) { cur++; } elsebreak; } if (cur >= k) { for (int i = 0; i < cur + 1; ++i) { vis[y - i][x - i] = true; vis[y - i][x + i] = true; } } };
for (int i = n - 1; i >= 0; --i) for (int j = 0; j < m; ++j) if (data[i][j] == '*') { if (!vis[i][j]) findCell(j, i); elsetryCell(j, i); } cout << (flag ? "YES" : "NO") << endl; } }
intmain(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, d; cin >> n >> d; vector<int> data(n); for (int i = 0; i < n; ++i) cin >> data[i]; bool flag = false; for (int i = 0; i < n; ++i) { if (data[i] == 1) { flag = true; break; } } if (!flag) { cout << 0 << endl; continue; }
vector<int> to(n, -1); vector<bool> deg(n, false); for (int i = 0; i < n; ++i) { int nxt = (i + n - d) % n; if (data[i] == 1 && data[nxt] == 1) { to[i] = nxt; deg[nxt] = true; } }
queue<pair<int, int>> q; for (int i = 0; i < n; ++i) if (!deg[i]) q.push({i, 0}); int ans = 0; int vis = 0; while (!q.empty()) { auto cur = q.front(); q.pop(); vis++; ans = max(ans, cur.second + 1); if (to[cur.first] == -1) continue; deg[to[cur.first]] = false; q.push({to[cur.first], cur.second + 1}); }
if (vis == n) cout << ans << endl; else cout << "-1" << endl; } }
intmain(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n; cin >> n; vector<int> data(n); for (int i = 0; i < n; ++i) cin >> data[i]; int l = 0, r = 2000;
auto cal = [&](int len) { int cur = 0, nxt = 1; memset(vis[nxt], true, sizeof(vis[nxt])); for (auto &item: data) { memset(vis[cur], false, sizeof(vis[cur])); for (int i = 0; i < len; ++i) { if (vis[nxt][i]) { if (i - item >= 0) vis[cur][i - item] = true; if (i + item < len) vis[cur][i + item] = true; } } swap(cur, nxt); } for (int i = 0; i < len; ++i) if (vis[nxt][i]) returntrue; returnfalse; };
while (l + 3 < r) { int mid = (l + r) >> 1; if (cal(mid + 1)) r = mid; else l = mid; } for (int i = l + 5; i >= l - 5; --i) { if (!cal(i + 1)) { cout << i + 1 << endl; break; } } } }