Problem p02601 (C++) — buggy submission, verdict: Runtime Error


// Problem: B - Magic 2
// Contest: AtCoder - M-SOLUTIONS Programming Contest 2020
// URL: https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define y1 y114514
#define elif else if
#define y2 y1919810
typedef pair<int, int> PII;
typedef vector<int> VI;
// #define int long long
#define all(x) x.begin(), x.end()
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define range(i, s, t) for (int i = s; i <= (int)t; i++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
long long qread() {
  char c = getchar();
  int neg = 1;
  long long val = 0;
  while (c != '-' && !isdigit(c))
    c = getchar();
  if (c == '-')
    c = getchar(), neg = -1;
  while (isdigit(c))
    val = (val << 3) + (val << 1) + c - '0', c = getchar();
  return neg * val;
}
int K, A, B, C;
void dfs(int k, int a, int b, int c) {
  if (k == K) {
    if (b > a && c > b) {
      puts("Yes");
      exit(0);
    }
    return;
  }
  dfs(k + 1, a * 2, b, c);
  dfs(k + 1, a, b * 2, c);
  dfs(k + 1, a, b, c * 2);
}
void solve() {
  A = qread();
  B = qread();
  C = qread();
  K = qread();
  dfs(0, A, B, C);
  puts("No");
}
int main() {
  int T = 1;
  // T = qread();
  while (T--)
    solve();
  return 0;
}


Error: 0

Fixed submission:


// Problem: B - Magic 2
// Contest: AtCoder - M-SOLUTIONS Programming Contest 2020
// URL: https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define y1 y114514
#define elif else if
#define y2 y1919810
typedef pair<int, int> PII;
typedef vector<int> VI;
// #define int long long
#define all(x) x.begin(), x.end()
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define range(i, s, t) for (int i = s; i <= (int)t; i++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
long long qread() {
  char c = getchar();
  int neg = 1;
  long long val = 0;
  while (c != '-' && !isdigit(c))
    c = getchar();
  if (c == '-')
    c = getchar(), neg = -1;
  while (isdigit(c))
    val = (val << 3) + (val << 1) + c - '0', c = getchar();
  return neg * val;
}
int K, A, B, C;
int vis[9][9][9][9];
void dfs(int k, int a, int b, int c) {
  vis[k][a][b][c] = 1;
  if (k == K) {
    if (b > a && c > b) {
      puts("Yes");
      exit(0);
    }
    return;
  }
  if (!vis[k + 1][a * 2][b][c])
    dfs(k + 1, a * 2, b, c);
  if (!vis[k + 1][a][b * 2][c])
    dfs(k + 1, a, b * 2, c);
  if (!vis[k + 1][a][b][c * 2])
    dfs(k + 1, a, b, c * 2);
}
void solve() {
  A = qread();
  B = qread();
  C = qread();
  K = qread();
  dfs(0, A, B, C);
  puts("No");
}
int main() {
  int T = 1;
  // T = qread();
  while (T--)
    solve();
  return 0;
}