Submission #43433923


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll epow(ll a, ll k) {
    ll ans = 1;
    while (k > 0) {
        if (k & 1) ans = ans * a;
        a = a * a;
        k >>= 1;
    }
    return ans;
}
bool isPossible(ll N, ll K, ll currentSum, ll currentTerm) {
    if(N == K) return true;
    if (currentSum == N && currentTerm == K) {
        return true;
    }
    if (currentSum > N || currentTerm > K) {
        return false;
    }
    for (int m = 0; m <= N; m++) {
        int newSum = currentSum + epow(3, m);
        int newTerm = currentTerm + 1;
        if (isPossible(N, K, newSum, newTerm)) {
            return true;
        }
    }
    return false;
}

int main() {
    int T;cin>>T;
    while(T--){
        ll n,k;cin>>n>>k;
        if(isPossible(n,k,0LL,0LL)) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Submission Info

Submission Time
Task A - Ternary Decomposition
User Sagor0078
Language C++ (GCC 9.2.1)
Score 0
Code Size 902 Byte
Status RE
Exec Time 2205 ms
Memory 1051368 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 1
AC × 1
TLE × 5
RE × 1
Set Name Test Cases
Sample sample-01.txt
All in-01.txt, in-02.txt, in-03.txt, in-04.txt, in-05.txt, in-06.txt, sample-01.txt
Case Name Status Exec Time Memory
in-01.txt TLE 2205 ms 3160 KiB
in-02.txt RE 795 ms 1051368 KiB
in-03.txt TLE 2205 ms 3216 KiB
in-04.txt TLE 2205 ms 3288 KiB
in-05.txt TLE 2205 ms 3228 KiB
in-06.txt TLE 2205 ms 3176 KiB
sample-01.txt AC 23 ms 3500 KiB