QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#357661 | #8129. Binary Sequence | kevinyang# | WA | 48ms | 18560kb | C++17 | 983b | 2024-03-19 07:25:27 | 2024-03-19 07:25:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
string tobin(int x){
string s = "";
while(x){
if(x%2==0){
s.push_back('0');
}
else{
s.push_back('1');
}
x/=2;
}
reverse(s.begin(),s.end());
return s;
}
string next(string s){
int cnt = 1;
string ans = "";
for(int i = 1; i<=s.size(); i++){
if(i==s.size() || s[i] != s[i-1]){
ans+=tobin(cnt);
ans.push_back(s[i-1]);
cnt = 1;
}
else{
cnt++;
}
}
return ans;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
vector<string>ans(39);
string cur = "1";
ans[1] = cur;
for(int i = 2; i<=38; i++){
cur = next(cur);
ans[i] = cur;
}
while(t--){
int n,m;
cin >> n >> m;
if(n<=38){
if(ans[n].size()<=m){
cout << "0\n";
}
else{
cout << ans[n][(int)ans[n].size()-1-m] << '\n';
}
}
else{
int i = n%2 + 36;
cout << ans[i][m] << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 41ms
memory: 17788kb
input:
10 4 0 4 1 4 2 4 3 4 4 4 5 4 6 6 3 6 7 118999881999119725 3
output:
1 1 0 1 1 1 0 1 1 0
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 48ms
memory: 18560kb
input:
10 28 69772 10 7908 4 3198 4 85913 14 52729 3 20445 9 88912 17 23743 25 37356 2 97697
output:
0 0 0 0 0 0 0 0 0 0
result:
ok 10 numbers
Test #3:
score: -100
Wrong Answer
time: 35ms
memory: 18372kb
input:
100 29 110358 18 13645 18 590344 36 550462 11 133055 8 769352 11 265432 7 158530 12 29189 2 830361 11 584395 31 693707 7 879812 19 25069 21 616926 3 85158 31 675739 17 118385 24 315535 29 59615 10 33445 17 609235 8 738138 20 209540 4 287616 32 522302 26 959741 5 453537 27 74313 28 296289 28 857972 2...
output:
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0
result:
wrong answer 41st numbers differ - expected: '1', found: '0'