Submission #1352131

#TimeUsernameProblemLanguageResultExecution timeMemory
1352131edoBliskost (COI23_bliskost)C++20
100 / 100
77 ms5840 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void yesno(int x) { cout << (x ? "da\n" : "ne\n"); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  string s, t;
  cin >> n >> k >> s >> t;

  ll f = 0, f1 = 0;
  auto norm = [&](ll &x) {
    x %= 26;
    if (x < 0)
      x += 26;
  };

  auto val = [&](char c) -> int { return c - 'a'; };

  for (int i = 0; i < n; ++i) {
    if (i & 1) {
      f -= val(s[i]);
      f1 -= val(t[i]);
    } else {
      f += val(s[i]);
      f1 += val(t[i]);
    }
  }

  norm(f);
  norm(f1);

  yesno(f1 == f);

  while (k--) {
    int x;
    char a;
    cin >> x >> a, --x;
    int old = val(s[x]);
    int neww = val(a);
    if (x & 1 ^ 1) {
      f += neww - old;
    } else {
      f += old - neww;
    }
    norm(f);
    yesno(f == f1);
    s[x] = a;
  }

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...