QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#57739#2923. Code Guessingwtcherr#AC ✓3ms3728kbC++202.9kb2022-10-22 19:15:182022-10-22 19:15:20

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-22 19:15:20]
  • Judged
  • Verdict: AC
  • Time: 3ms
  • Memory: 3728kb
  • [2022-10-22 19:15:18]
  • Submitted

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define IO ios_base::sync_with_stdio(0), cin.tie(0)
const int mod = 1e9 + 7;
template <typename T>
void readArray(vector<T> &A)
{
    for (T &i : A)
        cin >> i;
}
template <typename T>
void readArray(vector<vector<T>> &A)
{
    for (vector<T> &i : A)
        readArray(i);
}
template <typename T>
void printArray(vector<T> A)
{
    for (T i : A)
        cout << i << " ";
    cout << endl;
}
ll fastPow(ll a, ll b, ll m = mod)
{
    a %= m;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
bool isPrime(ll n, int iter = 5)
{
    if (n < 4)
        return n == 2 || n == 3;
    for (int i = 0; i < iter; i++)
    {
        int a = 2 + rand() % (n - 3);
        if (fastPow(a, n - 1, n) != 1)
            return false;
    }
    return true;
}
ll inv(ll n, ll m = mod)
{
    return fastPow(n, m - 2);
}
ll mul(ll a, ll b, ll m = mod)
{
    return (a * b) % m;
}
ll add(ll a, ll b, ll m = mod)
{
    return (a + b + m) % m;
}
int p, q;
vector<pii> ans;
void ch(vector<int> A)
{
    for (int i = 0; i < 4; i++)
    {
        if (A[i] == -1)
        {
            for (int j = 1; j <= 9; j++)
            {
                A[i] = j;
                ch(A);
            }
            return;
        }
    }
    // printArray(A);
    for (int i = 1; i < 4; i++)
    {
        if (A[i] <= A[i - 1])
            return;
    }
    pii a = {-1, -1};
    for (int i = 0; i < 4; i++)
    {
        if (A[i] != q && A[i] != p)
        {
            if (a.f == -1)
                a.f = A[i];
            else
                a.s = A[i];
        }
    }
    ans.push_back(a);
}
void solve()
{
    cin >> p >> q;
    string s;
    cin >> s;
    vector<int> A(4, -1);
    bool flg = true;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == 'A')
        {
            if (flg)
                A[i] = p, flg = false;
            else
                A[i] = q;
        }
    }
    ch(A);
    if (ans.size() == 1)
        cout << ans.begin()->f << " " << ans.begin()->s;
    else
        cout << -1;
}
void trials()
{
    int t, tt;
    for (cin >> t, tt = t; t--; cout << endl)
    {
        // cout << "Case #" << tt - t << ": ";
        solve();
    }
}
int main()
{
    // freopen("","r",stdin);
    IO;
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3556kb

input:

3 4
BBAA

output:

1 2

result:

ok single line: '1 2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

3 7
BBAA

output:

1 2

result:

ok single line: '1 2'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3724kb

input:

3 9
BBAA

output:

1 2

result:

ok single line: '1 2'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3560kb

input:

5 6
BBAA

output:

-1

result:

ok single line: '-1'

Test #5:

score: 0
Accepted
time: 3ms
memory: 3560kb

input:

6 7
AABB

output:

8 9

result:

ok single line: '8 9'

Test #6:

score: 0
Accepted
time: 3ms
memory: 3676kb

input:

3 7
AABB

output:

8 9

result:

ok single line: '8 9'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

1 7
AABB

output:

8 9

result:

ok single line: '8 9'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4 5
AABB

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

1 4
ABBA

output:

2 3

result:

ok single line: '2 3'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

3 6
ABBA

output:

4 5

result:

ok single line: '4 5'

Test #11:

score: 0
Accepted
time: 3ms
memory: 3556kb

input:

4 7
ABBA

output:

5 6

result:

ok single line: '5 6'

Test #12:

score: 0
Accepted
time: 3ms
memory: 3560kb

input:

5 9
ABBA

output:

-1

result:

ok single line: '-1'

Test #13:

score: 0
Accepted
time: 3ms
memory: 3564kb

input:

1 5
ABBA

output:

-1

result:

ok single line: '-1'

Test #14:

score: 0
Accepted
time: 2ms
memory: 3652kb

input:

2 7
ABBA

output:

-1

result:

ok single line: '-1'

Test #15:

score: 0
Accepted
time: 2ms
memory: 3712kb

input:

1 9
ABBA

output:

-1

result:

ok single line: '-1'

Test #16:

score: 0
Accepted
time: 2ms
memory: 3560kb

input:

2 8
BAAB

output:

1 9

result:

ok single line: '1 9'

Test #17:

score: 0
Accepted
time: 2ms
memory: 3540kb

input:

3 8
BAAB

output:

-1

result:

ok single line: '-1'

Test #18:

score: 0
Accepted
time: 2ms
memory: 3624kb

input:

2 6
BAAB

output:

-1

result:

ok single line: '-1'

Test #19:

score: 0
Accepted
time: 3ms
memory: 3648kb

input:

4 5
BAAB

output:

-1

result:

ok single line: '-1'

Test #20:

score: 0
Accepted
time: 3ms
memory: 3548kb

input:

6 8
ABAB

output:

7 9

result:

ok single line: '7 9'

Test #21:

score: 0
Accepted
time: 3ms
memory: 3636kb

input:

4 8
ABAB

output:

-1

result:

ok single line: '-1'

Test #22:

score: 0
Accepted
time: 3ms
memory: 3640kb

input:

3 7
ABAB

output:

-1

result:

ok single line: '-1'

Test #23:

score: 0
Accepted
time: 3ms
memory: 3624kb

input:

5 7
ABAB

output:

-1

result:

ok single line: '-1'

Test #24:

score: 0
Accepted
time: 2ms
memory: 3504kb

input:

1 3
ABAB

output:

-1

result:

ok single line: '-1'

Test #25:

score: 0
Accepted
time: 3ms
memory: 3644kb

input:

2 4
BABA

output:

1 3

result:

ok single line: '1 3'

Test #26:

score: 0
Accepted
time: 2ms
memory: 3708kb

input:

2 5
BABA

output:

-1

result:

ok single line: '-1'

Test #27:

score: 0
Accepted
time: 3ms
memory: 3676kb

input:

3 5
BABA

output:

-1

result:

ok single line: '-1'

Test #28:

score: 0
Accepted
time: 3ms
memory: 3640kb

input:

7 9
BABA

output:

-1

result:

ok single line: '-1'

Test #29:

score: 0
Accepted
time: 3ms
memory: 3728kb

input:

6 9
ABBA

output:

7 8

result:

ok single line: '7 8'

Test #30:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

2 5
BAAB

output:

-1

result:

ok single line: '-1'