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

/*/ Author: KaySeeKay /*/

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

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast")
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for (int i = 0; i < n; i++)
#define fn1 for (int i = 1; i <= n; i++)
#define fm for (int j = 0; j < m; j++)
#define fm1 for (int j = 1; j <= m; j++)
#define fi first
#define se second
#define endl '\\n'
#define PI 3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int N = 2e6 + 5;
const int INF = 1e18L;
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug
 * begins----------------------------------/*/
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args> inline string arrStr(T arr, int n) {
  stringstream s;
  s << "[";
  for (int i = 0; i < n - 1; i++)
    s << arr[i] << ",";
  s << arr[n - 1] << "]";
  return s.str();
}
#define trace(args...)                                                         \\
  {                                                                            \\
    __trace_begin(__LINE__);                                                   \\
    __trace(split(#args, ',').begin(), args);                                  \\
  }
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template <typename T> inline void __trace_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T> inline void __trace_out_var(T *val) {
  cerr << arrStr(val, 10);
}
template <typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }

template <typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
int dp[N];
inline int add(int x, int y, int mod) {
  if (y >= mod)
    y %= mod;
  if (x >= mod)
    x %= mod;
  x += y;
  return (x >= mod ? x - mod : x);
}
inline int mul(int x, int y, int mod) {
  if (x >= mod)
    x %= mod;
  if (y >= mod)
    y %= mod;
  return (x * y) % mod;
}
inline int sub(int x, int y, int mod) {
  x -= y;
  if (x + mod <= 0) {
    x %= mod;
  }
  return (x < 0 ? x + mod : x);
}
int PowerMod(int x, int n, int mod) {
  int res = 1;
  for (; n > 0;) {
    if (n & 1) {
      res = mul(res, x, mod);
    }
    x = mul(x, x, mod);
    n /= 2;
  }
  return res;
}
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;
  int T = 1;
  // cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int ans = PowerMod(10, n, MOD);
    ans = add(ans, PowerMod(8, n, MOD), MOD);
    ans = sub(ans, mul(2, PowerMod(9, n, MOD), MOD), MOD);
    cout << ans;
  }

  return 0;
}
/*
2-2
3-54
4-974
5-14670
6-199262
*/

Error: TLE

Fixed submission:

/*/ Author: KaySeeKay /*/

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

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast")
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for (int i = 0; i < n; i++)
#define fn1 for (int i = 1; i <= n; i++)
#define fm for (int j = 0; j < m; j++)
#define fm1 for (int j = 1; j <= m; j++)
#define fi first
#define se second
#define endl '\\n'
#define PI 3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int N = 2e6 + 5;
const int INF = 1e18L;
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug
 * begins----------------------------------/*/
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args> inline string arrStr(T arr, int n) {
  stringstream s;
  s << "[";
  for (int i = 0; i < n - 1; i++)
    s << arr[i] << ",";
  s << arr[n - 1] << "]";
  return s.str();
}
#define trace(args...)                                                         \\
  {                                                                            \\
    __trace_begin(__LINE__);                                                   \\
    __trace(split(#args, ',').begin(), args);                                  \\
  }
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template <typename T> inline void __trace_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T> inline void __trace_out_var(T *val) {
  cerr << arrStr(val, 10);
}
template <typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }

template <typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
int dp[N];
vector<int> v;
int a, b, cnt;
void solve(int pos, int n) {
  if (pos == n) {
    a = 0, b = 0;
    for (auto i : v) {
      if (i == 0)
        a = 1;
      if (i == 9)
        b = 1;
    }
    if (a && b) {
      cnt += 1;
      cnt %= MOD;
    }
    return;
  }
  for (int i = 0; i <= 9; i++) {
    v.pb(i);
    solve(pos + 1, n);
    v.pop_back();
  }
}
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;
  int T = 1;
  // cin >> T;
  while (T--) {
    int n;
    cin >> n;
    solve(0, n);
    // trace(cnt);
    cout << cnt;
  }
  return 0;
}