QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227786 | #2933. Sequinary Numerals | Thallium54# | AC ✓ | 1ms | 5848kb | C++20 | 917b | 2023-10-27 23:12:01 | 2023-10-27 23:12:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
const int N = 2e5 + 100;
const int inf = 1e9;
const ll mod = 998244353;
ll p2[N], p3[N];
int main()
{
string s;
cin >> s;
reverse(s.begin(), s.end());
int n = s.size();
p3[0] = p2[0] = 1;
for(int i = 1; i < n; i++)
{
p3[i] = p3[i-1] * 3;
p2[i] = p2[i-1] * 2;
}
ll N = 0, K = 0;
for(int i = 0; i < n; i++)
{
ll x = s[i] - '0';
ll k = (p3[i]*x)/p2[i];
N += k;
ll A = p3[i]*x - k*p2[i];
K = K*2 + A;
N += K/p2[i];
K -= (K/p2[i]) * p2[i];
//cout << (p3[i]*x)/p2[i] << ' ' << A << ' ' << p2[i] << endl;
}
cout << N << ' ';
if(K != 0)
{
cout << K/gcd(K,p2[n-1]) << '/' << p2[n-1]/gcd(K,p2[n-1]);
}
cout << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5620kb
input:
2101
output:
10
result:
ok single line: '10 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
201
output:
5 1/2
result:
ok single line: '5 1/2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5836kb
input:
2010211122112221202012
output:
16541 873801/1048576
result:
ok single line: '16541 873801/1048576'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5504kb
input:
22222222222222222222222222222222
output:
1725755 572407425/1073741824
result:
ok single line: '1725755 572407425/1073741824'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
11111111111111111111111111111111
output:
862877 1646149249/2147483648
result:
ok single line: '862877 1646149249/2147483648'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
10000000000000000000000000000000
output:
287626 1264544299/2147483648
result:
ok single line: '287626 1264544299/2147483648'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
1
output:
1
result:
ok single line: '1 '
Test #8:
score: 0
Accepted
time: 1ms
memory: 5644kb
input:
2
output:
2
result:
ok single line: '2 '
Test #9:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
10
output:
1 1/2
result:
ok single line: '1 1/2'
Test #10:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
11
output:
2 1/2
result:
ok single line: '2 1/2'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
12
output:
3 1/2
result:
ok single line: '3 1/2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 5636kb
input:
20
output:
3
result:
ok single line: '3 '
Test #13:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
21
output:
4
result:
ok single line: '4 '
Test #14:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
22
output:
5
result:
ok single line: '5 '
Test #15:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
201000101020120002210001022
output:
99539 7418955/33554432
result:
ok single line: '99539 7418955/33554432'
Test #16:
score: 0
Accepted
time: 1ms
memory: 5508kb
input:
21012020111221210112111012122211
output:
1056241 54451731/134217728
result:
ok single line: '1056241 54451731/134217728'
Test #17:
score: 0
Accepted
time: 0ms
memory: 5548kb
input:
121200
output:
25 19/32
result:
ok single line: '25 19/32'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
22010
output:
18 3/8
result:
ok single line: '18 3/8'
Test #19:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
1102121021020020112221202220100
output:
565301 930420511/1073741824
result:
ok single line: '565301 930420511/1073741824'
Test #20:
score: 0
Accepted
time: 0ms
memory: 5848kb
input:
1022020000221011110121211
output:
47476 16343961/16777216
result:
ok single line: '47476 16343961/16777216'
Test #21:
score: 0
Accepted
time: 1ms
memory: 5808kb
input:
21100210121101
output:
698 349/2048
result:
ok single line: '698 349/2048'
Test #22:
score: 0
Accepted
time: 1ms
memory: 5508kb
input:
122110002
output:
97 61/256
result:
ok single line: '97 61/256'
Test #23:
score: 0
Accepted
time: 0ms
memory: 5772kb
input:
200200011120110
output:
806 6545/8192
result:
ok single line: '806 6545/8192'
Test #24:
score: 0
Accepted
time: 1ms
memory: 5800kb
input:
212020012222220200010110012112
output:
540506 7899177/8388608
result:
ok single line: '540506 7899177/8388608'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
21201001011
output:
222 19/64
result:
ok single line: '222 19/64'