Problem p02600 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 1111LL
#define cout1(x) cout << x << "\\n";
#define deb(x) cout << #x << " " << x << "\\n";
#define vii vector<pa>;
using namespace std;
#define MAXN 1000000ll

// template<typename... T>
// void read(T&... args){
//     ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
//     ((cout<<args<<"\\n"), ...);
// }

v visited(N);
vector<ll> ans = {-1};
v level(N);
v ind(N);
ll sz[N];

// void dfs(ll node, ll par){

//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }

//     }
//      ++sz[node];

// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }

// }
ll spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)

    spf[i] = i;

  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)

        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

ll power(ll x, unsigned ll y, ll p) {
  ll res = 1; // Initialize result

  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

auto primeFactors(ll n) {
  map<ll, ll> fact;
  // Print the number of 2s that divide n
  while (n % 2 == 0) {
    fact[2] += 1;
    n = n / 2;
  }

  for (ll i = 3; i <= sqrt(n); i = i + 2) {

    while (n % i == 0) {
      fact[i] += 1;
      n = n / i;
    }
  }
  if (n > 2)
    fact[n] += 1;
  return fact;
}
auto getFactorization(int x) {
  map<ll, ll> ret;
  ;
  while (x != 1) {
    ret[spf[x]] += 1;
    x = x / spf[x];
  }
  return ret;
}

void solve() {
  ll x;
  cin >> x;
  if (x >= 400 && x <= 599)
    cout1(8);
  if (x >= 600 && x <= 799)
    cout1(7);
  if (x >= 800 && x <= 999)
    cout1(6);
  if (x >= 1000 && x <= 1199)
    cout1(5);
  if (x >= 1200 && x <= 1399)
    cout1(4);
  if (x >= 1400 && x <= 1599)
    cout1(3);
  if (x >= 1600 && x <= 1799)
    cout1(2);
  if (x >= 1800 && x <= 1999)
    cout1(1);
}

int main() {
  fastio;
  ll tests = 1;
  // cin>>tests;
  while (tests--)
    solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 1111LL
#define cout1(x) cout << x << "\\n";
#define deb(x) cout << #x << " " << x << "\\n";
#define vii vector<pa>;
using namespace std;
#define MAXN 1000000ll

// template<typename... T>
// void read(T&... args){
//     ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
//     ((cout<<args<<"\\n"), ...);
// }

v visited(N);
vector<ll> ans = {-1};
v level(N);
v ind(N);
ll sz[N];

// void dfs(ll node, ll par){

//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }

//     }
//      ++sz[node];

// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }

// }
ll spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)

    spf[i] = i;

  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;

  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)

        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

ll power(ll x, unsigned ll y, ll p) {
  ll res = 1; // Initialize result

  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

auto primeFactors(ll n) {
  map<ll, ll> fact;
  // Print the number of 2s that divide n
  while (n % 2 == 0) {
    fact[2] += 1;
    n = n / 2;
  }

  for (ll i = 3; i <= sqrt(n); i = i + 2) {

    while (n % i == 0) {
      fact[i] += 1;
      n = n / i;
    }
  }
  if (n > 2)
    fact[n] += 1;
  return fact;
}
auto getFactorization(int x) {
  map<ll, ll> ret;
  ;
  while (x != 1) {
    ret[spf[x]] += 1;
    x = x / spf[x];
  }
  return ret;
}

ll solve() {
  ll x;
  cin >> x;
  if (x >= 400 && x <= 599)
    cout1(8);
  if (x >= 600 && x <= 799)
    cout1(7);
  if (x >= 800 && x <= 999)
    cout1(6);
  if (x >= 1000 && x <= 1199)
    cout1(5);
  if (x >= 1200 && x <= 1399)
    cout1(4);
  if (x >= 1400 && x <= 1599)
    cout1(3);
  if (x >= 1600 && x <= 1799)
    cout1(2);
  if (x >= 1800 && x <= 1999)
    cout1(1);
}

int main() {
  fastio;
  ll tests = 1;
  // cin>>tests;
  while (tests--)
    solve();
}