alexjercan/bugnet huggingface dataset:
Problem p01553 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[256][256][256];

int main() {
  int n;
  int const mod = 1000000007;
  while (cin >> n && n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int k = 0; k < n; k++) {
      char c;
      cin >> c;
      if (c == '-') {
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x][y] += dp[k][x][y];
          }
        }
      }

      if (c == 'D') {
        for (int x = 1; x <= k; x++) {
          for (int y = 1; y <= k; y++) {
            dp[k + 1][x - 1][y - 1] += dp[k][x][y] * x * y;
            dp[k + 1][x - 1][y - 1] %= mod;
          }
        }
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x][y] += dp[k][x][y] * y;
            dp[k + 1][x][y] %= mod;
          }
        }
      }

      if (c == 'U') {
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x][y] += dp[k][x][y] * x;
            dp[k + 1][x][y] %= mod;
          }
        }
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x + 1][y + 1] += dp[k][x][y];
            dp[k + 1][x + 1][y + 1] %= mod;
          }
        }
      }
    }

    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=n;j++){
    //         cout<<dp[n][i][j]<<" ";
    //         if(j==n)cout<<endl;
    //     }
    // }
    cout << dp[n][0][0] << endl;
  }
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[128][128][128];

int main() {
  int n;
  int const mod = 1000000007;
  while (cin >> n && n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int k = 0; k < n; k++) {
      char c;
      cin >> c;
      if (c == '-') {
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x][y] += dp[k][x][y];
          }
        }
      }

      if (c == 'D') {
        for (int x = 1; x <= k; x++) {
          for (int y = 1; y <= k; y++) {
            dp[k + 1][x - 1][y - 1] += dp[k][x][y] * x * y;
            dp[k + 1][x - 1][y - 1] %= mod;
          }
        }
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x][y] += dp[k][x][y] * y;
            dp[k + 1][x][y] %= mod;
          }
        }
      }

      if (c == 'U') {
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x][y] += dp[k][x][y] * x;
            dp[k + 1][x][y] %= mod;
          }
        }
        for (int x = 0; x <= k; x++) {
          for (int y = 0; y <= k; y++) {
            dp[k + 1][x + 1][y + 1] += dp[k][x][y];
            dp[k + 1][x + 1][y + 1] %= mod;
          }
        }
      }
    }

    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=n;j++){
    //         cout<<dp[n][i][j]<<" ";
    //         if(j==n)cout<<endl;
    //     }
    // }
    cout << dp[n][0][0] << endl;
  }
}
Problem p01553 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

#define MOD 1000000007

typedef long long ll;

ll dp[201][201][201] = {0}; // dp[n][rest U][rest empty box] = ??´????????°

int main() {
  int N;
  cin >> N;
  vector<int> v;
  for (int i = 0; i < N; ++i) {
    char c;
    cin >> c;
    if (c != '-') {
      v.push_back(c);
    }
  }
  N = v.size();

  if (N == 0) {
    cout << 1 << endl;
    return 0;
  }
  if (v[0] == 'D') {
    cout << 0 << endl;
    return 0;
  }

  dp[0][1][1] = 1; // v[0] = 'U'
  for (int i = 0; i < N - 1; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        if (v[i + 1] == 'U') {
          dp[i + 1][j + 1][k + 1] =
              (dp[i + 1][j + 1][k + 1] + dp[i][j][k]) % MOD;
          if (j >= 1) {
            dp[i + 1][j][k] = (dp[i + 1][j][k] + j * dp[i][j][k]) % MOD;
          }
        } else { // D
          if (k >= 1) {
            //						if (dp[i][j][k]) cout << i << " " << j << " " << k <<
            //" : " << dp[i][j][k] << endl;
            dp[i + 1][j][k] = (dp[i + 1][j][k] + k * dp[i][j][k]) % MOD;
            if (j >= 1) {
              dp[i + 1][j - 1][k - 1] =
                  (dp[i + 1][j - 1][k - 1] + j * k * dp[i][j][k]) % MOD;
            }
          }
        }
      }
    }
  }

  cout << dp[N - 1][0][0] << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

#define MOD 1000000007

typedef long long ll;

ll dp[201][201][201] = {0}; // dp[n][rest U][rest empty box] = ??´????????°

int main() {
  int N;
  cin >> N;
  vector<int> v;
  for (int i = 0; i < N; ++i) {
    char c;
    cin >> c;
    if (c != '-') {
      v.push_back(c);
    }
  }
  N = v.size();

  if (v[0] == 'D') {
    cout << 0 << endl;
    return 0;
  }

  dp[0][1][1] = 1; // v[0] = 'U'
  for (int i = 0; i < N - 1; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        if (v[i + 1] == 'U') {
          dp[i + 1][j + 1][k + 1] =
              (dp[i + 1][j + 1][k + 1] + dp[i][j][k]) % MOD;
          if (j >= 1) {
            dp[i + 1][j][k] = (dp[i + 1][j][k] + j * dp[i][j][k]) % MOD;
          }
        } else { // D
          if (k >= 1) {
            //						if (dp[i][j][k]) cout << i << " " << j << " " << k <<
            //" : " << dp[i][j][k] << endl;
            dp[i + 1][j][k] = (dp[i + 1][j][k] + k * dp[i][j][k]) % MOD;
            if (j >= 1) {
              dp[i + 1][j - 1][k - 1] =
                  (dp[i + 1][j - 1][k - 1] + j * k * dp[i][j][k]) % MOD;
            }
          }
        }
      }
    }
  }

  cout << dp[N - 1][0][0] << endl;
}
Problem p01553 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

ll add(ll a, ll b) { return (a + b + mod + mod) % mod; }

ll mul(ll a, ll b) { return (a * b) % mod; }

ll dp[201][201];

ll solve(string str) {
  if (str == "")
    return 1;
  dp[0][0] = 1;
  int n = str.size();

  ll uc = 0, dc = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ll a = dp[i][j];
      if (a == 0)
        continue;
      // cout<<i<<' '<<j<<' '<<a<<endl;
      if (str[i] == 'U') {
        dp[i + 1][j + 1] = add(dp[i + 1][j + 1], a);
        dp[i + 1][j] = add(dp[i + 1][j], mul(a, j));
      }
      if (str[i] == 'D') {
        ll k = i - dc - (uc - j);
        dp[i + 1][j] = add(dp[i + 1][j], mul(a, k));
        if (j > 0)
          dp[i + 1][j - 1] = add(dp[i + 1][j - 1], mul(j, mul(a, k)));
      }
    }
    if (str[i] == 'U')
      uc++;
    else
      dc++;
  }
  return dp[n][0];
}

int main() {
  int n;
  cin >> n;
  string str = "";
  for (int i = 0; i < n; i++) {
    char ch;
    cin >> ch;
    if (ch == '-')
      continue;
    str += ch;
  }
  cout << solve(str) << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

ll add(ll a, ll b) { return (a + b + mod + mod) % mod; }

ll mul(ll a, ll b) { return (a * b) % mod; }

map<vector<int>, ll> dp[201][201];
string S;

ll rec(int dep, int cnt, vector<int> v) {
  for (int i = 0; i < (int)v.size(); i++)
    if (v[i] < 0)
      return 0;
  if (dep == (int)S.size())
    return 1;
  if (dep > 0 && S[dep - 1] == 'U')
    cnt++;
  if (dp[dep][cnt].count(v))
    return dp[dep][cnt][v];
  ll res = 0;
  if ((v.empty() || v[0] > 0) && cnt > 0) {
    vector<int> next = v;
    for (int i = 0; i < (int)v.size(); i++)
      next[i]--;
    res = add(res, mul(cnt, rec(dep + 1, cnt - 1, next)));
  }
  for (int i = 0; i < (int)v.size(); i++) {

    vector<int> next;
    for (int j = 0; j < (int)v.size(); j++) {
      if (i != j)
        next.push_back(v[j] - 1);
    }
    sort(next.begin(), next.end());
    if (!next.empty() && next[0] < 0)
      continue;
    res = add(res, rec(dep + 1, cnt, next));
  }
  return dp[dep][cnt][v] = res;
}

int solve(string str) {
  if (str == "")
    return 1;
  vector<int> vec;
  int cnt = 0;
  for (int i = 0; i < (int)str.size(); i++) {
    if (str[i] == 'D')
      vec.push_back(i - 1);
  }
  S = str;
  return rec(0, cnt, vec);
}

int main() {
  int n;
  cin >> n;
  string str = "";
  for (int i = 0; i < n; i++) {
    char ch;
    cin >> ch;
    if (ch == '-')
      continue;
    str += ch;
  }
  cout << solve(str) << endl;
  return 0;
}
Problem p01553 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;
typedef long long ll;

int main() {
  ll dp[700] = {}, *dp0 = dp + 100, *dp1 = dp + 400;
  dp1[0] = 1;
  int n;
  cin >> n;
  while (n--) {
    char c;
    cin >> c;
    if (c == '-')
      continue;
    for (int j = 0; j < 210; j++) {
      dp0[j] = (j * dp1[j] +
                ((c == 'U') ? dp1[j - 1] : (j + 1) * (j + 1) * dp1[j + 1])) %
               (ll)(1e9 + 7);
    }
    swap(dp0, dp1);
  }
  cout << dp1[0] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
typedef long long ll;

int main() {
  ll dp[420] = {}, *dp0 = dp + 1, *dp1 = dp + 221;
  dp1[0] = 1;
  int n;
  cin >> n;
  while (n--) {
    char c;
    cin >> c;
    if (c == '-')
      continue;
    for (int j = 0; j < 210; j++) {
      dp0[j] = (j * dp1[j] +
                ((c == 'U') ? dp1[j - 1] : (j + 1) * (j + 1) * dp1[j + 1])) %
               (ll)(1e9 + 7);
    }
    swap(dp0, dp1);
  }
  cout << dp1[0] << endl;
  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

bool search(string *array, int length, string target) {
  string array_last = array[length - 1];
  array[length - 1] = target;

  int i;
  for (i = 0; array[i] != target; i++) {
  }
  array[length - 1] = array_last;
  if (i < length - 1) {
    return true;
  } else if (array_last == target) {
    return true;
  } else {
    return false;
  }
}

int main(void) {
  bool open = false;
  int n;
  cin >> n;
  string *u = new string[n];
  for (int i = 0; i < n; i++) {
    cin >> u[i];
  }

  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string t;
    cin >> t;
    if (search(u, n, t)) {
      if (open) {
        cout << "Closed by ";
      } else {
        cout << "Opened by ";
      }
      open = !open;
    } else {
      cout << "Unknown ";
    }
    cout << t << endl;
  }

  delete[] u;
  return 0;
}

Error: 0
0
1
2
3
---


Fixed submission:

#include <iostream>
#include <string>
using namespace std;

bool search(string *array, int length, string target) {
  string array_last = array[length - 1];
  array[length - 1] = target;

  int i;
  for (i = 0; array[i] != target; i++) {
  }
  array[length - 1] = array_last;
  if (i < length - 1) {
    return true;
  } else if (array_last == target) {
    return true;
  } else {
    return false;
  }
}

int main(void) {
  bool open = false;
  int n;
  cin >> n;
  string *u = new string[n];
  for (int i = 0; i < n; i++) {
    // getline(cin, u[i]);
    cin >> u[i];
    cerr << i << endl;
  }
  cerr << "---" << endl;

  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string t;
    // getline(cin, t);
    cin >> t;
    if (search(u, n, t)) {
      if (open) {
        cout << "Closed by ";
      } else {
        cout << "Opened by ";
      }
      open = !open;
    } else {
      cout << "Unknown ";
    }
    cout << t << endl;
  }

  delete[] u;
  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int N, M;
string U[257];

int main() {
  char s[14];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", s);
    U[i] = s;
  }
  scanf("%d", &M);
  bool opened = false;
  for (int i = 0; i < M; i++) {
    scanf("%s", s);
    const string *p = find(U, U + N, (string)s);
    if (p && !p->empty()) {
      opened = !opened;
      printf("%s by %s\\n", (opened ? "Opened" : "Closed"), s);
    } else {
      printf("Unknown %s\\n", s);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int N, M;
string U[256];

int main() {
  char s[11];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", s);
    U[i] = s;
  }
  scanf("%d", &M);
  bool opened = false;
  for (int i = 0; i < M; i++) {
    scanf("%s", s);
    const string *p = find(U, U + N, (string)s);
    if (p && !p->empty()) {
      opened = !opened;
      printf("%s by %s\\n", (opened ? "Opened" : "Closed"), s);
    } else {
      printf("Unknown %s\\n", s);
    }
  }
  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, M;
  int frag = 0;
  string U[256];
  string T;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> U[i];
  }
  cin >> M;
  for (int j = 0; j < M; j++) {
    cin >> T;
    for (int i = 0; i < N; i++) {
      if (T == U[i]) {
        frag += 1;

        if (frag % 2 == 0) {
          cout << "Closed by " << T << endl;
        }

        else {
          cout << "Opened by " << T << endl;
        }

        break;
      }
      if (i == N - 1) {
        cout << "Unknown " << T << endl;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, M;
  int frag = 0;
  string U[255];
  string T;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> U[i];
  }
  cin >> M;
  for (int j = 0; j < M; j++) {
    cin >> T;
    for (int i = 0; i < N; i++) {
      if (T == U[i]) {
        frag += 1;

        if (frag % 2 == 0) {
          cout << "Closed by " << T << endl;
        }

        else {
          cout << "Opened by " << T << endl;
        }

        break;
      }
      if (i == N - 1) {
        cout << "Unknown " << T << endl;
      }
    }
  }

  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string id[257];
  for (int i = 0; i < n; i++) {
    cin >> id[i];
  }
  int lock = 0;
  int m;
  cin >> m;
  string x;
  for (int i = 0; i < m; i++) {
    int cnt = 0;
    cin >> x;
    for (int j = 0; j < n; j++) {
      if (x == id[j]) {
        if (lock == 0) {
          lock = 1;
          cout << "Opened by " << x << endl;
        } else {
          lock = 0;
          cout << "Closed by " << x << endl;
        }
        continue;
      } else
        cnt++;
    }
    if (cnt == n) {
      cout << "Unknown " << x << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string id[11];
  for (int i = 0; i < n; i++) {
    cin >> id[i];
  }
  int lock = 0;
  int m;
  cin >> m;
  string x;
  for (int i = 0; i < m; i++) {
    int cnt = 0;
    cin >> x;
    for (int j = 0; j < n; j++) {
      if (x == id[j]) {
        if (lock == 0) {
          lock = 1;
          cout << "Opened by " << x << endl;
        } else {
          lock = 0;
          cout << "Closed by " << x << endl;
        }
        continue;
      } else
        cnt++;
    }
    if (cnt == n) {
      cout << "Unknown " << x << endl;
    }
  }

  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>

int main() {
  int n, m, flag = 0, i, j;
  char s[256][16], t[16];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%s", s[i]);
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%s", t);
    for (j = 0; j < n; j++) {
      if (!strcmp(t, s[j])) {
        if (!flag) {
          printf("Opened by %s\\n", t);
          flag = 1;
          break;
        } else {
          printf("Closed by %s\\n", t);
          flag = 0;
          break;
        }
      }
    }
    if (j == n)
      printf("Unknown %s\\n", t);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, i, j, o[256], s;
  char *u[256], t;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> u[i];
  }
  cin >> m;
  s = 0;
  for (j = 0; j < m; j++) {
    cin >> t;
    o[j] = 0;
    for (i = 0; i < n; i++) {
      if (t == *u[i]) {
        o[j] = 1;
        if (s == 0) {
          cout << "Opened by " << u[i] << "\\n";
          s = 1;
        }
        if (s == 1) {
          cout << "Closed by " << u[i] << "\\n";
        }
      }
    }
    if (o[j] == 0) {
      cout << "Unknown " << t << "\\n";
    }
  }
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n;
  map<string, int> F1;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    F1[s] = 1;
  }

  int m, f = 0;
  cin >> m;
  while (m--) {
    string s;
    cin >> s;
    if (F1[s]) {
      f++;
      if (f % 2)
        cout << "Opened by " << s << endl;
      else
        cout << "Closed by " << s << endl;
    } else {
      cout << "Unknown " << s << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  int N, M, flag = 0, CP = 0;
  char U[100][1000], T[1000];

  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> U[i];

  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> T;

    for (int j = 0; j < N; j++) {
      int count = 0;

      for (int k = 0; k < strlen(T); k++)
        if (U[j][k] == T[k])
          count++;

      if (count == strlen(T)) {
        flag = 1;
        CP++;
        break;
      } else
        flag = 0;
    }

    if (flag == 1) {
      if (CP % 2 == 1)
        cout << "Opened by " << T << endl;
      else
        cout << "Closed by " << T << endl;
    } else
      cout << "Unknown " << T << endl;
  }

  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  string str[256];
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  int m;
  cin >> m;
  int cnt = 0;
  for (int j = 0; j < m; j++) {
    string str2;
    cin >> str2;
    for (int k = 0; k < n; k++) {
      if (str[k] == str2) {
        cnt++;
        if (cnt % 2 == 1)
          cout << "Opened by " << str2 << endl;
        else
          cout << "Closed by " << str2 << endl;
        break;
      }
      if (k == n - 1) {
        cout << "Unknown " << str2 << endl;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  string str[100];
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  int m;
  cin >> m;
  int cnt = 0;
  for (int j = 0; j < m; j++) {
    string str2;
    cin >> str2;
    for (int k = 0; k < n; k++) {
      if (str[k] == str2) {
        cnt++;
        if (cnt % 2 == 1)
          cout << "Opened by " << str2 << endl;
        else
          cout << "Closed by " << str2 << endl;
        break;
      }
      if (k == n - 1) {
        cout << "Unknown " << str2 << endl;
      }
    }
  }
  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> U(N);
  for (auto &a : U) {
    cin >> a;
  }
  int M;
  cin >> M;
  int flag = 0, auth;
  for (int i = 0; i < M; i++) {
    string s;
    cin >> s;
    auth = 0;
    for (int j = 0; j < N; j++) {
      if (U[j] == s) {
        if (flag == 0) {
          cout << "Opened by " << s << endl;
          flag = 1;
        } else {
          cout << "Closed by " << s << endl;
          flag = 0;
        }
        auth = 1;
        break;
      }
      if (auth)
        break;
    }
    if (auth == 0)
      cout << "Unknown " << s << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int N;
    cin >> N;
    vector<string> U(N);
    for (auto &a : U) {
      cin >> a;
    }
    int M;
    cin >> M;
    int flag = 0, auth;
    for (int i = 0; i < M; i++) {
      string s;
      cin >> s;
      auth = 0;
      for (int j = 0; j < N; j++) {
        if (U[j] == s) {
          if (flag == 0) {
            cout << "Opened by " << s << endl;
            flag = 1;
          } else {
            cout << "Closed by " << s << endl;
            flag = 0;
          }
          auth = 1;
          break;
        }
        if (auth)
          break;
      }
      if (auth == 0)
        cout << "Unknown " << s << endl;
    }
  }
  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))
#define QWERTYR(c)                                                             \\
  (c == 'y' || c == 'u' || (c >= 'h' && c <= 'p') ? true : false)
typedef vector<int> Ivec;
typedef pair<int, int> pii; // (cst, to)

int main() {
  int n, m;
  map<string, bool> IDs;
  scanf("%d", &n);
  for (int i = 0; n > i; i++) {
    char str[11];
    scanf("%s", str);
    IDs[string(str)] = true;
  }
  scanf("%d", &m);
  bool state = false;
  for (int i = 0; m > i; i++) {
    char str[11];
    scanf("%s", str);
    if (IDs[string(str)]) {
      state = 1 - state;
      printf("%sed by %s\\n", state ? "Open" : "Clos", str);
    } else {
      printf("Unknown %s\\n", str);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))
#define QWERTYR(c)                                                             \\
  (c == 'y' || c == 'u' || (c >= 'h' && c <= 'p') ? true : false)
typedef vector<int> Ivec;
typedef pair<int, int> pii; // (cst, to)

int main() {
  int n, m;
  map<string, bool> IDs;
  scanf("%d", &n);
  for (int i = 0; n > i; i++) {
    char str[11];
    scanf("%s", str);
    IDs[string(str)] = true;
  }
  scanf("%d", &m);
  bool state = false;
  for (int i = 0; m + i; i++) {
    char str[11];
    scanf("%s", str);
    if (IDs[string(str)]) {
      state = 1 - state;
      printf("%sed by %s\\n", state ? "Open" : "Clo", str);
    } else {
      printf("Unknown %s\\n", str);
    }
  }

  return 0;
}