QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#553055 | #7692. Prof. Fumblemore and the Collatz Conjecture | SpaceQuark# | AC ✓ | 4ms | 18788kb | C++20 | 4.7kb | 2024-09-08 06:33:55 | 2024-09-08 06:33:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
/* TYPES */
#define tcT template <class T
#define tcTU tcT, class U
#define tcTUW tcTU, class W
using ll = long long;
using db = long double;
using str = string;
/* PAIRS */
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
/* VECTORS */
tcT > using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
using vi = V<int>;
using vvi = V<V<int>>;
using vb = V<bool>;
using vl = V<ll>;
using vvl = V<V<ll>>;
using vd = V<db>;
using vc = V<char>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;
#define sz(x) int(size(x)) // (ll)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define view(x, a) V<decltype(x)::value_type> (bg(x), bg(x)+a+1)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define lb lower_bound
#define ub upper_bound
#define sum(v) accumulate(all(v), 0ll)
/* UNORDERED MAP SET */
#define timeStamp() std::chrono::steady_clock::now()
struct custom_hash {static uint64_t xs(uint64_t x) {x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);} size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = timeStamp().time_since_epoch().count(); return xs(x + FIXED_RANDOM);} size_t operator()(const pl& p) const {static const uint64_t FIXED_RANDOM = timeStamp().time_since_epoch().count(); return xs((uint64_t)p.fi) + ((uint64_t)p.se) * FIXED_RANDOM;}};
tcTU > using UM = unordered_map<T, U, custom_hash>;
tcT > using US = unordered_set<T, custom_hash>;
using umll = UM<ll, ll>;
using umcl = UM<char, ll>;
using umsl = UM<str, ll>;
using usl = US<ll>;
using usc = US<char>;
using uss = US<str>;
#define has(s, x) (s.find(x) != end(s))
/* LOOPS */
#define FOR(i, s, e) for (ll i = (s); i < (e); ++i)
#define CFOR(i, s, e) for (ll i = (s); i <= (e); ++i)
#define ROF(i, e, s) for (ll i = (e)-1; i >= (s); --i)
#define each(a, x) for (auto &a : x)
#define eachkv(k, v, mp) for (auto &[k, v] : mp)
/* CONSTANTS */
const char nl = '\n';
const int MOD = 998244353; // 1e9+7;
const int MX = (int)2e6 + 5;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1}; // for every grid problem!!
const int dr[4]{1, -1, 1, -1}, dc[4]{1, 1, -1, -1}; // for every diagonal problem!!
mt19937 rng((uint32_t)timeStamp().time_since_epoch().count());
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
/* FUNCTIONS */
tcT > UM<T, ll> counter(V<T> &v){ UM<T, ll> mp; each(a, v){ if (mp.count(a)){mp[a]++;} else{mp[a] = 1;} } return mp;}
UM<char, ll> counter(str &v){ UM<char, ll> mp; each(a, v){ if (mp.count(a)){mp[a]++;} else{mp[a] = 1;} } return mp;}
tcTU > V<pair<T, U>> keyvals(UM<T, U> &mp){V<pair<T, U>> vp; eachkv(k,v,mp){vp.eb(k, v);} return vp;}
tcT > V<T> idxter(V<T> v){V<T> idxs(MX, -1);FOR(i,0,sz(v)){idxs[v[i]] = i;}return idxs;}
tcT > void remDup(V<T> &v) {sort(all(v)); v.erase(unique(all(v)), end(v));}
tcTU > void ese(T &t, const U &u) {auto it = t.find(u); t.erase(it);}
// [](const auto& a, const auto& b) {return a.se < b.se;}
/* TESTING */
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL);
#define rd(...) ([](auto&&... args) { (cin >> ... >> args); }(__VA_ARGS__))
#define rdv(v) each(x, v) { rd(x);}
#define wrtl(...) ([](auto&&... args) { (cout << ... << args) << endl; }(__VA_ARGS__))
#define YES wrtl("YES")
#define NO wrtl("NO")
vl dp(MX, 0);
// vvl dp(m, vl(n, 0)); // m x n
void solve(){
str s; rd(s);
ll n = sz(s);
if (s[n-1] != 'O'){
cout << "INVALID" << nl;
return;
}
FOR(i,0,n-1){
if (s[i] == 'O' && s[i+1] == 'O'){
cout << "INVALID" << nl;
return;
}
}
reverse(all(s));
ll res = (1ll << 48) + 1;
ll tmp;
for(ll i = 8; i <= (1ll << 60); i*=2){
tmp = i;
// dbg(tmp);
FOR(j,0,n){
if(s[j] == 'E'){
tmp *= 2;
if (tmp >= (1ll << 62)){ // 63 is negative
tmp = 0;
break;
}
} else if(s[j] == 'O'){
if ((tmp-1) % 3 != 0){
// dbg("not divis");
tmp = 0;
break;
}
tmp = (tmp-1)/3;
// maybe not?
if (tmp >= (1ll << 62)){
tmp = 0;
break;
}
}
}
// dbg(tmp);
if (tmp != 0 && (res > tmp)){
res = tmp;
}
}
if (res == (1ll << 48) + 1){
cout << "INVALID" << nl;
return;
}
cout << res << nl;
}
int main(){
fastio;
ll t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 18540kb
input:
EEOEO
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 4ms
memory: 18604kb
input:
EEOOEO
output:
INVALID
result:
ok single line: 'INVALID'
Test #3:
score: 0
Accepted
time: 0ms
memory: 18668kb
input:
OEOEOEOEOEOEOEEEEEEOEEEOEEEOEEEOEOEEOEEEO
output:
383
result:
ok single line: '383'
Test #4:
score: 0
Accepted
time: 0ms
memory: 18680kb
input:
OEOEEEEEOEOEEEEOEEEEOEOEOEEOEEEO
output:
931
result:
ok single line: '931'
Test #5:
score: 0
Accepted
time: 3ms
memory: 18740kb
input:
OEEOEEOEEOEOEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO
output:
641
result:
ok single line: '641'
Test #6:
score: 0
Accepted
time: 0ms
memory: 18740kb
input:
OEOEEOEEOEEOEEOEEEEOEEEOEOEOEEEEEO
output:
683
result:
ok single line: '683'
Test #7:
score: 0
Accepted
time: 0ms
memory: 18552kb
input:
OEEOEEEOEOEEEEOEEEEOEOEOEEOEEEO
output:
465
result:
ok single line: '465'
Test #8:
score: 0
Accepted
time: 4ms
memory: 18788kb
input:
OEEOEEOEOEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO
output:
481
result:
ok single line: '481'
Test #9:
score: 0
Accepted
time: 3ms
memory: 18544kb
input:
OEEOEOEO
output:
201
result:
ok single line: '201'
Test #10:
score: 0
Accepted
time: 0ms
memory: 18780kb
input:
OEEEEOEEOEOEEEOEOEEOEEEO
output:
133
result:
ok single line: '133'
Test #11:
score: 0
Accepted
time: 0ms
memory: 18788kb
input:
OEOEOEOEEOEEEEEEEEEEOEOEOEEOEEEO
output:
943
result:
ok single line: '943'
Test #12:
score: 0
Accepted
time: 3ms
memory: 18740kb
input:
OEEEOEEO
output:
301
result:
ok single line: '301'
Test #13:
score: 0
Accepted
time: 0ms
memory: 18604kb
input:
OEOEOEEEEEEOEOEEOEEOEEEEOEOEOEEOEEEO
output:
407
result:
ok single line: '407'
Test #14:
score: 0
Accepted
time: 0ms
memory: 18588kb
input:
OEOEOEOEOEOEEOEEEEOEEEOEEEOEEEOEOEEOEEEO
output:
191
result:
ok single line: '191'
Test #15:
score: 0
Accepted
time: 0ms
memory: 18668kb
input:
OEEEOEO
output:
605
result:
ok single line: '605'
Test #16:
score: 0
Accepted
time: 0ms
memory: 18700kb
input:
OEOEOEOEEOEEEEOEEEOEEEOEEEOEOEEOEEEO
output:
431
result:
ok single line: '431'
Test #17:
score: 0
Accepted
time: 0ms
memory: 18544kb
input:
OEOEEEOEEEOEOEOEEEOEEEEOEOEEEOEOEEOEEEO
output:
563
result:
ok single line: '563'
Test #18:
score: 0
Accepted
time: 3ms
memory: 18600kb
input:
OEEOEEEEEOEEOEEEO
output:
241
result:
ok single line: '241'
Test #19:
score: 0
Accepted
time: 0ms
memory: 18672kb
input:
OEEEOEEEEOEOEEEOEOEEOEEEO
output:
269
result:
ok single line: '269'
Test #20:
score: 0
Accepted
time: 0ms
memory: 18768kb
input:
EEOEOEOEEOEEEEOEOEEOEEOEEEEOEOEOEEOEEEO
output:
540
result:
ok single line: '540'
Test #21:
score: 0
Accepted
time: 0ms
memory: 18532kb
input:
OEOEOEOEOEOEEEEEEOEEEOEEEOEEEOEOEEOEEEO
output:
575
result:
ok single line: '575'
Test #22:
score: 0
Accepted
time: 0ms
memory: 18616kb
input:
EEOEEOEOEEEEEOEOEOEEEEEO
output:
868
result:
ok single line: '868'
Test #23:
score: 0
Accepted
time: 3ms
memory: 18592kb
input:
OEOEOEO
output:
26512143
result:
ok single line: '26512143'
Test #24:
score: 0
Accepted
time: 0ms
memory: 18676kb
input:
OEOEOEEO
output:
13256071
result:
ok single line: '13256071'
Test #25:
score: 0
Accepted
time: 3ms
memory: 18740kb
input:
EEO
output:
20
result:
ok single line: '20'
Test #26:
score: 0
Accepted
time: 2ms
memory: 18728kb
input:
EOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEE
output:
INVALID
result:
ok single line: 'INVALID'
Test #27:
score: 0
Accepted
time: 0ms
memory: 18700kb
input:
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEO
output:
43980465111040
result:
ok single line: '43980465111040'
Test #28:
score: 0
Accepted
time: 0ms
memory: 18668kb
input:
EEEEEEEEEEOEEEOEEEEOEOEEOEEEEEOEEEEEEEOEEOEEEEEEEO
output:
7321693729792
result:
ok single line: '7321693729792'
Test #29:
score: 0
Accepted
time: 0ms
memory: 18760kb
input:
EEEOEEEOEEOEEEEEOEEEEEEEOEEEEEEEEEEEEEEEEOEEEEEO
output:
1028529777000
result:
ok single line: '1028529777000'