QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#710153#7692. Prof. Fumblemore and the Collatz ConjecturebecaidoAC ✓1ms3856kbC++201.7kb2024-11-04 18:51:302024-11-04 18:51:32

Judging History

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

  • [2024-11-04 18:51:32]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3856kb
  • [2024-11-04 18:51:30]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

#define int long long
#define bigint __int128

const int INF = 1e18;
const int lim = 1ll << 47;

int n, ans;
string s;

bool istwo(bigint x) {
    bigint y = 1;
    while (y < x) y *= 2;
    return x == y;
}
int cal(bigint x) {
    for (int i = n; i >= 1; i--) {
        if (s[i] == 'O') {
            if ((x - 1) % 3 != 0) return INF;
            x--, x /= 3;
            if (x % 2 == 0) return INF;
        } else {
            x *= 2;
        }
        if (istwo(x)) return INF;
    }
    if (x > lim) return INF;
    return (int) x;
}

void solve() {
    cin >> s;
    n = s.size(), s = " " + s;
    if (s[n] != 'O') {
        cout << "INVALID\n";
        return;
    }
    FOR (i, 1, n - 1) if (s[i] == 'O' && s[i + 1] == 'O') {
        cout << "INVALID\n";
        return;
    }
    FOR (i, 1, n) if (s[i] != 'E' && s[i] != 'O') {
        cout << "INVALID\n";
        return;
    }
    ans = INF;
    bigint x = 1;
    FOR (i, 1, 70) {
        ans = min(ans, cal(x));
        x *= 2;
    }
    if (ans > lim) {
        cout << "INVALID\n";
        return;
    }
    cout << ans << '\n';
}

int32_t main() {
    Waimai;
    solve();
}

详细

Test #1:

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

input:

EEOEO

output:

12

result:

ok single line: '12'

Test #2:

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

input:

EEOOEO

output:

INVALID

result:

ok single line: 'INVALID'

Test #3:

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

input:

OEOEOEOEOEOEOEEEEEEOEEEOEEEOEEEOEOEEOEEEO

output:

383

result:

ok single line: '383'

Test #4:

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

input:

OEOEEEEEOEOEEEEOEEEEOEOEOEEOEEEO

output:

931

result:

ok single line: '931'

Test #5:

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

input:

OEEOEEOEEOEOEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

641

result:

ok single line: '641'

Test #6:

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

input:

OEOEEOEEOEEOEEOEEEEOEEEOEOEOEEEEEO

output:

683

result:

ok single line: '683'

Test #7:

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

input:

OEEOEEEOEOEEEEOEEEEOEOEOEEOEEEO

output:

465

result:

ok single line: '465'

Test #8:

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

input:

OEEOEEOEOEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

481

result:

ok single line: '481'

Test #9:

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

input:

OEEOEOEO

output:

201

result:

ok single line: '201'

Test #10:

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

input:

OEEEEOEEOEOEEEOEOEEOEEEO

output:

133

result:

ok single line: '133'

Test #11:

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

input:

OEOEOEOEEOEEEEEEEEEEOEOEOEEOEEEO

output:

943

result:

ok single line: '943'

Test #12:

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

input:

OEEEOEEO

output:

301

result:

ok single line: '301'

Test #13:

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

input:

OEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

407

result:

ok single line: '407'

Test #14:

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

input:

OEOEOEOEOEOEEOEEEEOEEEOEEEOEEEOEOEEOEEEO

output:

191

result:

ok single line: '191'

Test #15:

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

input:

OEEEOEO

output:

605

result:

ok single line: '605'

Test #16:

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

input:

OEOEOEOEEOEEEEOEEEOEEEOEEEOEOEEOEEEO

output:

431

result:

ok single line: '431'

Test #17:

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

input:

OEOEEEOEEEOEOEOEEEOEEEEOEOEEEOEOEEOEEEO

output:

563

result:

ok single line: '563'

Test #18:

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

input:

OEEOEEEEEOEEOEEEO

output:

241

result:

ok single line: '241'

Test #19:

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

input:

OEEEOEEEEOEOEEEOEOEEOEEEO

output:

269

result:

ok single line: '269'

Test #20:

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

input:

EEOEOEOEEOEEEEOEOEEOEEOEEEEOEOEOEEOEEEO

output:

540

result:

ok single line: '540'

Test #21:

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

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: 3628kb

input:

OEOEOEEO

output:

13256071

result:

ok single line: '13256071'

Test #25:

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

input:

EEO

output:

20

result:

ok single line: '20'

Test #26:

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

input:

EOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEE

output:

INVALID

result:

ok single line: 'INVALID'

Test #27:

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

input:

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEO

output:

43980465111040

result:

ok single line: '43980465111040'

Test #28:

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

input:

EEEEEEEEEEOEEEOEEEEOEOEEOEEEEEOEEEEEEEOEEOEEEEEEEO

output:

7321693729792

result:

ok single line: '7321693729792'

Test #29:

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

input:

EEEOEEEOEEOEEEEEOEEEEEEEOEEEEEEEEEEEEEEEEOEEEEEO

output:

1028529777000

result:

ok single line: '1028529777000'