QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#96310#2923. Code GuessingAbdelrahman_K#AC ✓2ms3452kbC++141.6kb2023-04-13 19:14:292023-04-13 19:14:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-13 19:14:31]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3452kb
  • [2023-04-13 19:14:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
const int N = 2e7 + 2;
vector<vector<int>> seq;
vector<int> w;
void gen(int ind, int mask) {
    if (ind == 4) {
        seq.push_back(w);
//        for (auto i : w) {
//            cerr << i << " ";
//        }
//        cerr << endl;
        return;
    }
    for (int i = w.size() ? w.back() + 1 : 1; i <= 9; i++) {
        if (mask >> i & 1)
            continue;
        w.push_back(i);
        gen(ind+1, mask | (1 << i));
        w.pop_back();
    }
}
int main() {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    string s;
    cin >> s;
    gen(0, 0);
    int cnt = 0;
    vector<int> ans;
    for (auto v : seq) {
        int a[4];
        memset(a, -1, sizeof a);
        int xx = x, yy = y;
        for (int i = 0; i < 4; i++) {
            if (s[i] == 'A') {
                if (xx)
                    a[i] = xx, xx = 0;
                else
                    a[i] = yy;
            }
        }
        vector<int> curr;
        bool valid = 1;
        for (int i = 0; i < 4; i++) {
            if (a[i] == -1) {
                curr.push_back(v[i]);
            }
            else {
                if (a[i] != v[i]) {
                    valid = 0;
                    break;
                }
            }
        }
        if (valid) {
            cnt++;
            ans = curr;
        }
    }
    if (cnt == 1) {
        for (auto i : ans) {
            cout << i << " ";
        }
    }
    else {
        cout << -1;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3452kb

input:

3 4
BBAA

output:

1 2 

result:

ok single line: '1 2 '

Test #2:

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

input:

3 7
BBAA

output:

1 2 

result:

ok single line: '1 2 '

Test #3:

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

input:

3 9
BBAA

output:

1 2 

result:

ok single line: '1 2 '

Test #4:

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

input:

5 6
BBAA

output:

-1

result:

ok single line: '-1'

Test #5:

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

input:

6 7
AABB

output:

8 9 

result:

ok single line: '8 9 '

Test #6:

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

input:

3 7
AABB

output:

8 9 

result:

ok single line: '8 9 '

Test #7:

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

input:

1 7
AABB

output:

8 9 

result:

ok single line: '8 9 '

Test #8:

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

input:

4 5
AABB

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

1 4
ABBA

output:

2 3 

result:

ok single line: '2 3 '

Test #10:

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

input:

3 6
ABBA

output:

4 5 

result:

ok single line: '4 5 '

Test #11:

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

input:

4 7
ABBA

output:

5 6 

result:

ok single line: '5 6 '

Test #12:

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

input:

5 9
ABBA

output:

-1

result:

ok single line: '-1'

Test #13:

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

input:

1 5
ABBA

output:

-1

result:

ok single line: '-1'

Test #14:

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

input:

2 7
ABBA

output:

-1

result:

ok single line: '-1'

Test #15:

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

input:

1 9
ABBA

output:

-1

result:

ok single line: '-1'

Test #16:

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

input:

2 8
BAAB

output:

1 9 

result:

ok single line: '1 9 '

Test #17:

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

input:

3 8
BAAB

output:

-1

result:

ok single line: '-1'

Test #18:

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

input:

2 6
BAAB

output:

-1

result:

ok single line: '-1'

Test #19:

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

input:

4 5
BAAB

output:

-1

result:

ok single line: '-1'

Test #20:

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

input:

6 8
ABAB

output:

7 9 

result:

ok single line: '7 9 '

Test #21:

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

input:

4 8
ABAB

output:

-1

result:

ok single line: '-1'

Test #22:

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

input:

3 7
ABAB

output:

-1

result:

ok single line: '-1'

Test #23:

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

input:

5 7
ABAB

output:

-1

result:

ok single line: '-1'

Test #24:

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

input:

1 3
ABAB

output:

-1

result:

ok single line: '-1'

Test #25:

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

input:

2 4
BABA

output:

1 3 

result:

ok single line: '1 3 '

Test #26:

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

input:

2 5
BABA

output:

-1

result:

ok single line: '-1'

Test #27:

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

input:

3 5
BABA

output:

-1

result:

ok single line: '-1'

Test #28:

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

input:

7 9
BABA

output:

-1

result:

ok single line: '-1'

Test #29:

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

input:

6 9
ABBA

output:

7 8 

result:

ok single line: '7 8 '

Test #30:

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

input:

2 5
BAAB

output:

-1

result:

ok single line: '-1'