QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537621#7692. Prof. Fumblemore and the Collatz Conjectureyzkkai#AC ✓0ms3876kbC++201.7kb2024-08-30 16:47:452024-08-30 16:47:45

Judging History

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

  • [2024-08-30 16:47:45]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3876kb
  • [2024-08-30 16:47:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using LL = long long;
using pii = pair<int, int>;
#define sz(x) signed(size(x))

void solve() {
    string s;
    cin >> s;

    if (s == "") {
        cout << 2 << '\n';
        return;
    }

    int n = sz(s);
    for (int i = 1; i < n; ++i)
        if (s[i - 1] == 'O' && s[i] == 'O') {
            cout << "INVALID\n";
            return;
        }

    if (s.back() != 'O') {
        cout << "INVALID\n";
        return;
    }

    vector<unsigned __int128> two(127, 1);

    for (int i = 1; i < 127; ++i)
        two[i] = two[i - 1] * 2;
    set<unsigned __int128> st(two.begin(), two.end());

    ll ans = -1;
    reverse(s.begin(), s.end());
    for(int i = 1;i <= 64;i ++){
        unsigned __int128 cur = two[i];
        int f = 1;
        for(char c : s){
            if(c == 'O'){
                cur -= 1;
                if(cur % 3){
                    f = 0;
                    break;
                }
                cur /= 3;
                if(cur % 2 == 0){
                    f = 0;
                    break;
                }
            } else {
                cur *= 2;
            }

            if (st.count(cur)) {
                f = 0;
                break;
            }
        }
        if(f){
            if(ans == -1){
                ans = cur;
            } else {
                if(cur > (1ll<<47))
                    continue;
                ans = min(ans, (ll)cur);
            }
        }
    }
    cout << ans << "\n";
    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3832kb

input:

EEOEO

output:

12

result:

ok single line: '12'

Test #2:

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

input:

EEOOEO

output:

INVALID

result:

ok single line: 'INVALID'

Test #3:

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

input:

OEOEOEOEOEOEOEEEEEEOEEEOEEEOEEEOEOEEOEEEO

output:

383

result:

ok single line: '383'

Test #4:

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

input:

OEOEEEEEOEOEEEEOEEEEOEOEOEEOEEEO

output:

931

result:

ok single line: '931'

Test #5:

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

input:

OEEOEEOEEOEOEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

641

result:

ok single line: '641'

Test #6:

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

input:

OEOEEOEEOEEOEEOEEEEOEEEOEOEOEEEEEO

output:

683

result:

ok single line: '683'

Test #7:

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

input:

OEEOEEEOEOEEEEOEEEEOEOEOEEOEEEO

output:

465

result:

ok single line: '465'

Test #8:

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

input:

OEEOEEOEOEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

481

result:

ok single line: '481'

Test #9:

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

input:

OEEOEOEO

output:

201

result:

ok single line: '201'

Test #10:

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

input:

OEEEEOEEOEOEEEOEOEEOEEEO

output:

133

result:

ok single line: '133'

Test #11:

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

input:

OEOEOEOEEOEEEEEEEEEEOEOEOEEOEEEO

output:

943

result:

ok single line: '943'

Test #12:

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

input:

OEEEOEEO

output:

301

result:

ok single line: '301'

Test #13:

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

input:

OEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

407

result:

ok single line: '407'

Test #14:

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

input:

OEOEOEOEOEOEEOEEEEOEEEOEEEOEEEOEOEEOEEEO

output:

191

result:

ok single line: '191'

Test #15:

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

input:

OEEEOEO

output:

605

result:

ok single line: '605'

Test #16:

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

input:

OEOEOEOEEOEEEEOEEEOEEEOEEEOEOEEOEEEO

output:

431

result:

ok single line: '431'

Test #17:

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

input:

OEOEEEOEEEOEOEOEEEOEEEEOEOEEEOEOEEOEEEO

output:

563

result:

ok single line: '563'

Test #18:

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

input:

OEEOEEEEEOEEOEEEO

output:

241

result:

ok single line: '241'

Test #19:

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

input:

OEEEOEEEEOEOEEEOEOEEOEEEO

output:

269

result:

ok single line: '269'

Test #20:

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

input:

EEOEOEOEEOEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

540

result:

ok single line: '540'

Test #21:

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

input:

OEOEOEOEOEOEEEEEEOEEEOEEEOEEEOEOEEOEEEO

output:

575

result:

ok single line: '575'

Test #22:

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

input:

EEOEEOEOEEEEEOEOEOEEEEEO

output:

868

result:

ok single line: '868'

Test #23:

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

input:

OEOEOEO

output:

26512143

result:

ok single line: '26512143'

Test #24:

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

input:

OEOEOEEO

output:

13256071

result:

ok single line: '13256071'

Test #25:

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

input:

EEO

output:

20

result:

ok single line: '20'

Test #26:

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

input:

EOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEE

output:

INVALID

result:

ok single line: 'INVALID'

Test #27:

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

input:

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEO

output:

43980465111040

result:

ok single line: '43980465111040'

Test #28:

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

input:

EEEEEEEEEEOEEEOEEEEOEOEEOEEEEEOEEEEEEEOEEOEEEEEEEO

output:

7321693729792

result:

ok single line: '7321693729792'

Test #29:

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

input:

EEEOEEEOEEOEEEEEOEEEEEEEOEEEEEEEEEEEEEEEEOEEEEEO

output:

1028529777000

result:

ok single line: '1028529777000'