QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308926 | #8129. Binary Sequence | ucup-team087# | WA | 103ms | 14280kb | C++14 | 3.0kb | 2024-01-20 13:49:22 | 2024-01-20 13:49:24 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr int LIM = 1001001;
constexpr int SMALL = 80;
// https://www.njohnston.ca/2010/11/the-binary-look-and-say-sequence/
constexpr int U = 10;
string S[U] = {"1", "11", "10", "110", "1110", "11110", "100", "1100", "11100", "111100"};
int L[U] = {0, 3, 0, 3, 0, 7, 0, 3, 0, 7};
int R[U] = {2, 1, 5, 4, 6, 4, 9, 8, 10, 8};
int INI[U] = {1, 2, 2, 3, 4, 5, 3, 4, 5, 6};
int dp[SMALL + 1][U];
bitset<LIM> brt[SMALL + 1];
int main() {
for (int u = 0; u < U; ++u) {
--L[u];
--R[u];
dp[0][u] = INI[u];
}
for (int n = 1; n <= SMALL; ++n) {
for (int u = 0; u < U; ++u) {
dp[n][u] = min(((~L[u]) ? dp[n - 1][L[u]] : 0) + dp[n - 1][R[u]], LIM);
}
// cerr<<"dp["<<n<<"] = ";pv(dp[n],dp[n]+U);
}
{
vector<int> crt{0};
for (int n = 0; n <= SMALL; ++n) {
int len = 0;
vector<int> nxt;
for (const int u : crt) {
nxt.push_back(R[u]);
if (~L[u]) nxt.push_back(L[u]);
for (int x = S[u].size(); --x >= 0; ) {
brt[n][len++] = S[u][x] - '0';
if (len == LIM) goto done;
}
}
done:{}
// cerr<<n<<": "<<len<<"; ";for(int i=0;i<len&&i<100;++i)cerr<<brt[n][i];cerr<<endl;
assert(len == dp[n][0]);
crt.swap(nxt);
}
}
assert(brt[SMALL - 0] == brt[SMALL - 2]);
assert(brt[SMALL - 1] == brt[SMALL - 3]);
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
Int N;
int M;
scanf("%lld%d", &N, &M);
--N;
N = (SMALL - 1) + (N - (SMALL - 1)) % 2;
int ans = 0;
if (M < dp[N][0]) {
ans = brt[N][M];
}
printf("%d\n", ans);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 94ms
memory: 14236kb
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: -100
Wrong Answer
time: 103ms
memory: 14280kb
input:
10 28 69772 10 7908 4 3198 4 85913 14 52729 3 20445 9 88912 17 23743 25 37356 2 97697
output:
1 1 1 1 1 1 1 1 1 1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'