#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain(){ int t; cin >> t;
while (t--) { int n; cin >> n;
deque<int> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } while (!a.empty() && a.front() == 0) { a.pop_front(); } while (!a.empty() && a.back() == 0) { a.pop_back(); } int ans = 0; if (!a.empty()) { ans = 1; for (int i = 0; i < a.size(); i++) { if (a[i] == 0) { ans = 2; } } } cout << ans << endl; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain(){ int t; cin >> t;
while (t--) { int n, x, y; cin >> n >> x >> y; x--, y--;
vector<int> res(n, -1); int now = 0; for (int i = x; i != y; i = (i + 1) % n) { res[i] = now; now ^= 1; } now = 0; for (int i = x; i != y; i = (i + n - 1) % n) { res[i] = now; now ^= 1; } res[x] = 0; res[y] = 2 - (res[(y + 1) % n] == 0 && res[(y + n - 1) % n] == 0);
for (int i = 0; i < n; i++) { cout << res[i] << " "; } cout << endl; }
vector a(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } }
vector minn(n, vector(m, vector<ll>(m))); for (int i = 0; i < n; i++) { for (int len = 0; len < m; len++) { ll sum = 0; int l = 0, r = len; for (int j = r; j > l; j--) { sum += a[i][j]; }
ll now = inf; for (int t = 0; t < 2 * m; t++) { sum += a[i][l]; minn[i][l][r] = now = min(now + K, sum); sum -= a[i][r]; l = (l - 1 + m) % m; r = (r - 1 + m) % m; } } }
vector dp(n, vector<ll>(m, inf)); // 走到第 i 行,第 j 列的最小代价 for (int j = 0; j < m; j++) { dp[0][j] = minn[0][0][j]; } for (int i = 1; i < n; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k <= j; k++) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + minn[i][k][j]); } } } cout << dp.back().back() << endl; }