alexjercan/bugnet huggingface dataset:
Problem p01726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long MOD = 11411411419191919LL;

vector<long long> C;
string S, T;
long long modpow[320000];
bool find(long long E) {
  long long V = lower_bound(C.begin(), C.end(), E) - C.begin();
  if (C[V] == E)
    return true;
  return false;
}
int main() {
  modpow[0] = 1;
  for (int i = 1; i < 320000; i++) {
    modpow[i] = modpow[i - 1] * 127;
    modpow[i] %= MOD;
  }
  cin >> T >> S;
  long long p = 0;
  for (int i = 0; i < S.size(); i++) {
    p += modpow[S.size() - 1 - i] * S[i];
    p %= MOD;
  }
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 127; j++) {
      if (S[i] == j)
        continue;
      if (j < 65)
        continue;
      if (j > 122)
        continue;
      if (j >= 91 && j < 97)
        continue;
      long long sa = modpow[S.size() - i - 1] * (j - S[i]);
      sa %= MOD;
      long long P = (p + MOD + sa) % MOD;
      C.push_back(P);
    }
  }
  sort(C.begin(), C.end());
  long long W = 0;
  for (int i = 0; i < S.size(); i++) {
    W += modpow[S.size() - i - 1] * T[i];
    W %= MOD;
  }
  int OK = 0;
  if (find(W) == true) {
    OK++;
  }
  for (int i = S.size(); i < T.size(); i++) {
    W -= modpow[S.size() - 1] * T[i - S.size()];
    W = (W + MOD * 127) % MOD;
    W *= 127;
    W += T[i];
    W %= MOD;
    if (find(W) == true)
      OK++;
  }
  cout << OK << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long MOD = 1LL << 55;

vector<long long> C;
string S, T;
long long modpow[320000];
bool find(long long E) {
  long long L = 0, R = C.size(), M;
  while (L <= R) {
    M = (L + R) / 2;
    if (M >= C.size())
      M = C.size() - 1;
    if (C[M] == E)
      return true;
    if (C[M] < E)
      L = M;
    if (C[M] > E)
      R = M - 1;
  }
  return false;
}
int main() {
  modpow[0] = 1;
  for (int i = 1; i < 320000; i++) {
    modpow[i] = modpow[i - 1] * 127;
    modpow[i] %= MOD;
  }
  cin >> T >> S;
  long long p = 0;
  for (int i = 0; i < S.size(); i++) {
    p += modpow[S.size() - 1 - i] * S[i];
    p %= MOD;
  }
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 127; j++) {
      if (S[i] == j)
        continue;
      if (j < 65)
        continue;
      if (j > 122)
        continue;
      if (j >= 91 && j < 97)
        continue;
      long long sa = modpow[S.size() - i - 1] * (j - S[i]);
      sa %= MOD;
      long long P = (p + MOD + sa) % MOD;
      C.push_back(P);
    }
  }
  sort(C.begin(), C.end());
  long long W = 0;
  for (int i = 0; i < S.size(); i++) {
    W += modpow[S.size() - i - 1] * T[i];
    W %= MOD;
  }
  int OK = 0;
  if (find(W) == true) {
    OK++;
  }
  for (int i = S.size(); i < T.size(); i++) {
    W -= modpow[S.size() - 1] * T[i - S.size()];
    W = (W + MOD * 127) % MOD;
    W *= 127;
    W += T[i];
    W %= MOD;
    if (find(W) == true)
      OK++;
  }
  cout << OK << endl;
  return 0;
}
Problem p01726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#define base 257
using namespace std;
string s, t;
unsigned long long power[333333], val[333333];
int main() {
  power[0] = 1;
  for (int i = 1; i < 333333; i++)
    power[i] = power[i - 1] * base;
  cin >> s >> t;
  int s1 = t.size(), s2 = s.size(), s3 = s.size() - t.size() + 1;
  unsigned long long v = 0;
  for (int i = 0; i < s1; i++)
    v = v * base + s[i];
  val[0] = v;
  for (int i = s1; i < s2; i++)
    v = v * base - power[s1] * s[i - s1] + s[i], val[i - s1 + 1] = v;
  sort(val, val + s3);
  unsigned long long u = 0;
  for (int i = 0; i < s1; i++)
    u = u * base + t[i];
  int ret = 0;
  for (int i = 0; i < s1; i++) {
    for (char j = 'a'; j <= 'z'; j++) {
      if (j != t[i]) {
        u += power[s1 - i - 1] * (j - t[i]);
        ret += upper_bound(val, val + s3, u) - lower_bound(val, val + s3, u);
        u -= power[s1 - i - 1] * (j - t[i]);
      }
    }
    for (char j = 'A'; j <= 'Z'; j++) {
      if (j != t[i]) {
        u += power[s1 - i - 1] * (j - t[i]);
        ret += upper_bound(val, val + s3, u) - lower_bound(val, val + s3, u);
        u -= power[s1 - i - 1] * (j - t[i]);
      }
    }
  }
  printf("%d\\n", ret);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#define base 257
using namespace std;
string s, t;
unsigned long long power[300000], val[300000];
int main() {
  power[0] = 1;
  for (int i = 1; i < 300000; i++)
    power[i] = power[i - 1] * base;
  cin >> s >> t;
  unsigned long long v = 0;
  for (int i = 0; i < t.size(); i++)
    v = v * base + s[i];
  val[0] = v;
  for (int i = t.size(); i < s.size(); i++)
    v = v * base - power[t.size()] * s[i - t.size()] + s[i],
    val[i - t.size() + 1] = v;
  sort(val, val + t.size() - s.size() + 1);
  unsigned long long u = 0;
  for (int i = 0; i < t.size(); i++)
    u = u * base + t[i];
  int ret = 0;
  for (int i = 0; i < t.size(); i++) {
    for (char j = 'a'; j <= 'z'; j++) {
      u += power[t.size() - i - 1] * (j - s[i]);
      if (binary_search(val, val + t.size() - s.size() + 1, u)) {
        ret++;
      }
      u -= power[t.size() - i - 1] * (j - s[i]);
    }
  }
  printf("%d\\n", ret);
  return 0;
}
Problem p01726 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  unsigned long long h = 0;
  unsigned long long B = 99999999947ULL;
  for (int i = 0; i < T.size(); i++) {
    h = h * B + T[i];
  }
  vector<unsigned long long> hashes;
  unsigned long long b = 1;
  for (int i = T.size() - 1; i >= 0; i--) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (T[i] != c) {
        hashes.push_back(h - T[i] * b + c * b);
      }
    }
    for (char c = 'A'; c <= 'Z'; c++) {
      if (T[i] != c) {
        hashes.push_back(h - T[i] * b + c * b);
      }
    }
    b *= B;
  }
  sort(begin(hashes), end(hashes));
  unsigned long long sh = 0;
  for (int i = 0; i < T.size(); i++) {
    sh = sh * B + S[i];
  }
  int ans = 0;
  for (int i = 0;; i++) {
    ans += binary_search(begin(hashes), end(hashes), sh);
    if (i + T.size() >= S.size())
      break;
    sh = sh * B - b * S[i] + S[i + T.size()];
  }
  cout << ans << endl;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <unordered_set>

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  unsigned long long h = 0;
  unsigned long long B = 1000000007;
  for (int i = 0; i < T.size(); i++) {
    h = h * B + T[i];
  }
  unordered_set<unsigned long long> hashes;
  unsigned long long b = 1;
  for (int i = T.size() - 1; i >= 0; i--) {
    for (char c = 'a'; c <= 'z'; c++) {
      hashes.insert(h - T[i] * b + c * b);
    }
    for (char c = 'A'; c <= 'A'; c++) {
      hashes.insert(h - T[i] * b + c * b);
    }
    b *= B;
  }
  hashes.erase(h);
  unsigned long long sh = 0;
  for (int i = 0; i < T.size(); i++) {
    sh = sh * B + S[i];
  }
  int ans = 0;
  for (int i = 0;; i++) {
    ans += hashes.count(sh);
    if (i + T.size() >= S.size())
      break;
    sh = sh * B - b * S[i] + S[i + T.size()];
  }
  cout << ans << endl;
}
Problem p01726 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef unsigned long long wolf;
char S[310000];
char T[310000];
long long pow[310000];
wolf P = 1299709;
// long long mod=1145148931919LL;
int main() {
  scanf("%s%s", S, T);
  int n = strlen(S);
  int m = strlen(T);
  pow[0] = 1;
  for (int i = 1; i < 310000; i++)
    pow[i] = pow[i - 1] * P;
  // for(int i=0;i<10;i++)printf("%lld\\n",pow[i]);
  vector<wolf> v;
  wolf val = 0;
  for (int i = 0; i < m; i++)
    val = (val + (T[i]) * pow[i]);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) {
      if (T[i] - 'a' == j)
        continue;
      wolf tmp = (val - (T[i]) * pow[i]);
      v.push_back((tmp + pow[i] * ('a' + j)));
      //	printf("%d %d: %lld\\n",i,j,(tmp+pow[i]*j)%mod);
    }
    for (int j = 0; j < 26; j++) {
      if (T[i] - 'A' == j)
        continue;
      wolf tmp = (val - (T[i]) * pow[i]);
      v.push_back((tmp + pow[i] * ('A' + j)));
      //	printf("%d %d: %lld\\n",i,j,(tmp+pow[i]*j)%mod);
    }
  }
  std::sort(v.begin(), v.end());
  int ret = 0;
  wolf now = 0;
  for (int i = n - 1; i >= 0; i--) {
    now = now * P;
    if (i < n - m)
      now = (now - (S[i + m]) * pow[m]);
    now = (now + (S[i]));
    if (i <= n - m && binary_search(v.begin(), v.end(), now))
      ret++;
  }
  printf("%d\\n", ret);
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
char S[310000];
char T[310000];
long long pow[2][301000];
long long P = 10007;
long long mod[3] = {1145148931919LL, 1145141919893LL, 1000000009LL};
long long now[3];
int main() {
  scanf("%s%s", S, T);
  int n = strlen(S);
  int m = strlen(T);
  for (int i = 0; i < n; i++) {
    if ('a' <= S[i] && S[i] <= 'z')
      S[i] -= 'a';
    else
      S[i] = S[i] - 'A' + 26;
  }
  for (int i = 0; i < m; i++) {
    if ('a' <= T[i] && T[i] <= 'z')
      T[i] -= 'a';
    else
      T[i] = T[i] - 'A' + 26;
  }
  for (int j = 0; j < 2; j++) {
    pow[j][0] = 1;
    for (int i = 1; i < 301000; i++)
      pow[j][i] = pow[j][i - 1] * P % mod[j];
  }
  vector<long long> v[2];

  for (int k = 0; k < 2; k++) {
    long long val = 0;
    for (int i = 0; i < m; i++)
      val = (val + (T[i]) * pow[k][i]) % mod[k];
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < 52; j++) {
        if (T[i] == j)
          continue;
        long long tmp = (mod[k] + val - (T[i]) * pow[k][i] % mod[k]) % mod[k];
        v[k].push_back((tmp + pow[k][i] * j) % mod[k]);
      }
    }
    std::sort(v[k].begin(), v[k].end());
  }
  int ret = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 2; j++) {
      now[j] = now[j] * P % mod[j];
      if (i < n - m)
        now[j] = (mod[j] + now[j] - (S[i + m]) * pow[j][m] % mod[j]) % mod[j];
      now[j] = (now[j] + (S[i])) % mod[j];
    }
    if (i <= n - m && binary_search(v[0].begin(), v[0].end(), now[0]) &&
        binary_search(v[1].begin(), v[1].end(), now[1]))
      ret++;
  }
  printf("%d\\n", ret);
}
Problem p01730 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double, double> P;

double D(P a, P b) {
  int x1 = floor(a.F / 10) * 10, x2 = floor(b.F / 10) * 10,
      y1 = floor(a.S / 10) * 10, y2 = floor(b.S / 10) * 10;
  if (x1 != a.F && x2 != b.F && x1 == x2 && y1 != y2) {
    double d1 = fabs(a.F - x1), d2 = fabs(b.F - x2);
    return fabs(a.S - b.S) + min(d1 + d2, 20 - d1 - d2);
  } else if (y1 != a.S && y2 != b.S && y1 == y2 && x1 != x2) {
    double d1 = fabs(a.S - y1), d2 = fabs(b.S - y2);
    return fabs(a.F - b.F) + min(d1 + d2, 20 - d1 - d2);
  }
  return fabs(a.F - b.F) + fabs(a.S - b.S);
}

int n, M = 1 << 29;
P a[11111];
double solve(int x, int y, double s, double t) {
  double ans = M;
  for (double l = x - 30; l <= x + 30; l += s) {
    for (double r = y - 30; r <= y + 30; r += t) {
      double d = 0;
      for (int i = 0; i < n; i++)
        d = max(d, D(a[i], P(l, r)));
      ans = min(ans, d);
    }
  }
  return ans;
}

int main() {
  cin >> n;
  double Max = -M, Mix = M, May = -M, Miy = M;
  for (int i = 0; i < n; i++) {
    cin >> a[i].F >> a[i].S;
    Max = max(Max, a[i].F + a[i].S);
    Mix = min(Mix, a[i].F + a[i].S);
    May = max(May, a[i].F - a[i].S);
    Miy = min(Miy, a[i].F - a[i].S);
  }
  int xx = (Max + Mix) / 2, yy = (May + Miy) / 2;
  int x = floor((double)(xx + yy) / 20) * 10,
      y = floor((double)(xx - yy) / 20) * 10;
  printf("%.10f\\n", min(solve(x, y, 10, 0.5), solve(x, y, 0.5, 10)));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double, double> P;

double D(P a, P b) {
  int x1 = floor(a.F / 10) * 10, x2 = floor(b.F / 10) * 10,
      y1 = floor(a.S / 10) * 10, y2 = floor(b.S / 10) * 10;
  if (x1 != a.F && x2 != b.F && x1 == x2 && y1 != y2) {
    double d1 = fabs(a.F - x1), d2 = fabs(b.F - x2);
    return fabs(a.S - b.S) + min(d1 + d2, 20 - d1 - d2);
  } else if (y1 != a.S && y2 != b.S && y1 == y2 && x1 != x2) {
    double d1 = fabs(a.S - y1), d2 = fabs(b.S - y2);
    return fabs(a.F - b.F) + min(d1 + d2, 20 - d1 - d2);
  }
  return fabs(a.F - b.F) + fabs(a.S - b.S);
}

int n, M = 1 << 29;
P a[11111];
double solve(int x, int y, double s, double t) {
  double ans = M;
  for (double l = x - 100; l <= x + 100; l += s) {
    for (double r = y - 100; r <= y + 100; r += t) {
      double d = 0;
      for (int i = 0; i < n; i++)
        d = max(d, D(a[i], P(l, r)));
      ans = min(ans, d);
    }
  }
  return ans;
}

int main() {
  cin >> n;
  double Max = -M, Mix = M, May = -M, Miy = M;
  for (int i = 0; i < n; i++) {
    cin >> a[i].F >> a[i].S;
    Max = max(Max, a[i].F + a[i].S);
    Mix = min(Mix, a[i].F + a[i].S);
    May = max(May, a[i].F - a[i].S);
    Miy = min(Miy, a[i].F - a[i].S);
  }
  int xx = (Max + Mix) / 2, yy = (May + Miy) / 2;
  int x = floor((double)(xx + yy) / 20) * 10,
      y = floor((double)(xx - yy) / 20) * 10;
  printf("%.10f\\n", min(solve(x, y, 10, 0.5), solve(x, y, 0.5, 10)));
  return 0;
}
Problem p01731 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct edge {
  int u, v;

  edge() {}
  ~edge() {}

  edge(int a, int b) : u(a), v(b) {}
};

void rec(int ind, int depth, vector<edge> &ve, vector<string> &vm) {
  for (int _ = 0; _ < depth; ++_)
    cout << '.';
  cout << vm[ind] << endl;
  for (edge &e : ve) {
    if (e.u == ind) {
      rec(e.v, depth + 1, ve, vm);
    }
  }
}

int main() {
  int n;
  vector<edge> ve;
  vector<string> vm;
  cin >> n;
  for (int j = 0; j < n; ++j) {
    int k;
    string m;
    cin >> k >> m;
    ve.push_back(edge(k - 1, j));
    vm.push_back(m);
  }
  rec(0, 0, ve, vm);
  return 0;
}

Error: TLE

Fixed submission:

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

struct edge {
  int u, v;

  edge() {}
  ~edge() {}

  edge(int a, int b) : u(a), v(b) {}
};

void rec(int ind, int depth, vector<edge> &ve, vector<string> &vm) {
  for (int _ = 0; _ < depth; ++_)
    cout << '.';
  cout << vm[ind] << endl;
  for (edge &e : ve) {
    if (e.u == ind) {
      rec(e.v, depth + 1, ve, vm);
    }
  }
}

int main() {
  int n;
  vector<edge> ve;
  vector<string> vm;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    ve.resize(0);
    vm.resize(0);
    for (int j = 0; j < n; ++j) {
      int k;
      string m;
      cin >> k >> m;
      ve.push_back(edge(k - 1, j));
      vm.push_back(m);
    }
    rec(0, 0, ve, vm);
  }
  return 0;
}
Problem p01731 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int n;
int k[1111];
string s[1111];

void dfs(int d, int dd) {
  while (1) {
    int ni = -1;
    rep(i, n) {
      if (k[i] == d) {
        ni = i;
        break;
      }
    }
    if (ni == -1)
      return;
    rep(i, dd) cout << ".";
    cout << s[ni] << endl;
    k[ni] = -1;
    dfs(ni + 1, dd + 1);
  }
}

int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  rep(i, n) cin >> k[i] >> s[i];
  dfs(0, 0);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int n;
int k[55];
string s[55];

void dfs(int d, int dd) {
  while (1) {
    int ni = -1;
    rep(i, n) {
      if (k[i] == d) {
        ni = i;
        break;
      }
    }
    if (ni == -1)
      return;
    rep(i, dd) cout << ".";
    cout << s[ni] << endl;
    k[ni] = -1;
    dfs(ni + 1, dd + 1);
  }
}

int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  rep(i, n) cin >> k[i] >> s[i];
  dfs(0, 0);
  return 0;
}
Problem p01731 (C++) — buggy submission, verdict: Runtime Error

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

struct mes {
  mes *pre;
  vector<mes *> fol;
  string m;
};
vector<mes> vec;

void dfs(mes m, int d) {
  for (int i = 0; i < d; i++)
    cout << ".";
  cout << m.m << endl;
  for (int i = 0; i < m.fol.size(); i++)
    dfs(*m.fol[i], d + 1);
}
int main() {
  int n, k;
  string str;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    mes me;
    vec.push_back(me);
  }
  for (int i = 1; i <= n; i++) {
    cin >> k >> str;
    vec[i].pre = &vec[k];
    vec[i].m = str;
    vec[k].fol.push_back(&vec[i]);
  }
  dfs(vec[1], 0);
}

Error: WA

Fixed submission:

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

struct mes {
  mes *pre;
  vector<mes *> fol;
  string m;
};
vector<mes> vec;

void dfs(mes m, int d) {
  for (int i = 0; i < d; i++)
    cout << ".";
  cout << m.m << endl;
  for (int i = 0; i < m.fol.size(); i++)
    dfs(*m.fol[i], d + 1);
}
int main() {
  int n, k;
  string str;
  cin >> n;
  for (int i = 0; i < n; i++) {
    mes me;
    vec.push_back(me);
  }
  for (int i = 0; i < n; i++) {
    cin >> k >> str;
    vec[i].pre = &vec[k - 1];
    vec[i].m = str;
    vec[k - 1].fol.push_back(&vec[i]);
  }
  // dfs(vec[0],0);
}
Problem p01733 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

int main() {
  int N;
  cin >> N;
  map<pair<int, int>, ll> m;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ll w;
    cin >> w;
    m[make_pair(x, y)] = w;
  }

  ll ans = 0;
  for (auto p : m) {
    int x = p.first.first;
    int y = p.first.second;

    ll w = 0;
    if (m.find(make_pair(x, y)) != m.end())
      w += m[make_pair(x, y)];
    if (m.find(make_pair(x + 1, y)) != m.end())
      w += m[make_pair(x + 1, y)];
    if (m.find(make_pair(x, y + 1)) != m.end())
      w += m[make_pair(x, y + 1)];
    if (m.find(make_pair(x + 1, y + 1)) != m.end())
      w += m[make_pair(x + 1, y + 1)];

    ll j = 0;
    if (m.find(make_pair(x, y)) != m.end())
      j += m[make_pair(x, y)];
    if (m.find(make_pair(x - 1, y)) != m.end())
      j += m[make_pair(x - 1, y)];
    if (m.find(make_pair(x, y + 1)) != m.end())
      j += m[make_pair(x, y + 1)];
    if (m.find(make_pair(x - 1, y + 1)) != m.end())
      j += m[make_pair(x - 1, y + 1)];

    ans = max(ans, max(j, w));
  }

  cout << ans << " / 1" << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

int main() {
  int N;
  cin >> N;
  vector<ll> x(N), y(N);
  vector<pair<ll, int>> w(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> w[i].first;
    w[i].second = i;
  }

  sort(w.begin(), w.end());
  reverse(w.begin(), w.end());

  ll a = 0, b = 1;
  for (int i = 0; i < N; i++) {
    if (a > 2 * w[i].first)
      continue;
    for (int j = i + 1; j < N; j++) {
      ll n = w[i].first + w[j].first;
      ll m = abs(x[w[i].second] - x[w[j].second]) *
             abs(y[w[i].second] - y[w[j].second]);

      if (a * m < b * n) {
        a = n;
        b = m;
      }
    }
  }

  cout << a << " / " << b << endl;

  return 0;
}
Problem p01733 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<P, ll> mp;
  for (int i = 0; i < n; i++) {
    ll x, y, w;
    cin >> x >> y >> w;
    mp[make_pair(x, y)] = w;
  }
  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    ll cnt = itr->second;
    queue<ll> que;
    for (int i = 0; i < 9; i++) {
      ll nx = itr->first.first + dx[i];
      ll ny = itr->first.second + dy[i];
      P tmp = make_pair(nx, ny);
      if (mp.count(tmp) > 0)
        cnt += mp[tmp];
      if (mp.find(tmp) != mp.end())
        que.push(mp[tmp]);
      else
        que.push(0);
      if (que.size() == 3) {
        ans = max(cnt, ans);
        for (int j = 0; j < 2; j++) {
          ll q = que.front();
          que.pop();
          cnt -= q;
        }
      }
    }
    ans = max(cnt, ans);
  }
  cout << ans << " / " << 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<P, ll> mp;
  for (int i = 0; i < n; i++) {
    ll x, y, w;
    cin >> x >> y >> w;
    mp[make_pair(x, y)] = w;
  }
  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    ll cnt = itr->second;
    queue<ll> que;
    map<P, ll> mp_tmp(mp);
    for (int i = 0; i < 9; i++) {
      ll nx = itr->first.first + dx[i];
      ll ny = itr->first.second + dy[i];
      P tmp = make_pair(nx, ny);
      if (mp.count(tmp) > 0)
        cnt += mp_tmp.at(make_pair(nx, ny));
      else
        mp_tmp[make_pair(nx, ny)] = 0;
      que.push(mp_tmp.at(make_pair(nx, ny)));
      if (que.size() == 3) {
        ans = max(cnt, ans);
        for (int j = 0; j < 2; j++) {
          ll q = que.front();
          que.pop();
          cnt -= q;
        }
      }
    }
    ans = max(cnt, ans);
  }
  cout << ans << " / " << 1 << endl;
  return 0;
}