1371A. Magical Sticks

  1. int main() {
  2. cin.tie(nullptr)->sync_with_stdio(false);
  3. int _; for (cin >> _; _--;) {
  4. ll n; cin >> n;
  5. cout << (n + 1) / 2 << "\n";
  6. }
  7. }

1371B. Magical Calendar

  1. int main() {
  2. cin.tie(nullptr)->sync_with_stdio(false);
  3. int _; for (cin >> _; _--;) {
  4. ll n, r;
  5. cin >> n >> r;
  6. ll k = min(n - 1, r);
  7. cout << (k + 1) * k / 2 + (r >= n) << "\n";
  8. }
  9. }

1371C. A Cookie for You

  1. void solve() {
  2. ll a, b, n, m;
  3. cin >> a >> b >> n >> m;
  4. cout << (a + b >= n + m and min(a, b) >= m ? "YES\n" : "NO\n");
  5. }

1371D. Grid-00100

  1. const int maxn = 300;
  2. int A[maxn][maxn];
  3. void solve() {
  4. ll n, k;
  5. cin >> n >> k;
  6. cout << not not(k % n) * 2 << "\n";
  7. for (int i = 0; i < n; i += 1)
  8. for (int j = 0; j < n; j += 1) A[i][j] = 0;
  9. for (int i = 0; i < n; i += 1)
  10. for (int j = 0; j < n; j += 1)
  11. if (k) {
  12. A[j][(i + j) % n] = 1;
  13. k -= 1;
  14. }
  15. for (int i = 0; i < n; i += 1) {
  16. for (int j = 0; j < n; j += 1) cout << A[i][j];
  17. cout << "\n";
  18. }
  19. }